bookmarklet - How to get the source of a javascript bookmark from itself when running? -


i have bookmark that's javascript bookmark. example:

javascript:alert('hi'); 

i'd able source of running javascript bookmark, within bookmark itself, in pseudocode:

javascript:alert(currentlyexecutingscript.text); 

which alert

javascript:alert(currentlyexecutingscript.text); 

how can this? prefer cross browser solutions, fine chrome specific solutions!

why interested in this? because i'm writing bookmarklet refers itself.

as location refers current page's url, , javascript bookmarks not change location, not possible in current browsers.

however, is possible want in javascript:

javascript:void function f(){alert(f.tostring())}() 

that alert following:

function f(){alert(f.tostring())} 

the tostring() method, when called on function, returns string representing source code of function (see https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/function/tostring).

credit

@sergeseredenko suggested use void.

when using immediately-invoked function expression, void can used force function keyword treated expression instead of declaration.
https://developer.mozilla.org/en-us/docs/web/javascript/reference/operators/void#immediately_invoked_function_expressions


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -