javascriptaddress-bar

javascript in an address bar


I have a small problem. When im executing a javascript in an address bar and the function that i'm calling there returns a value. The page moves to a new page. To prevent this, i use a void(0) at the end. But once this is done, how can i capture the returned value of the function.

For eg:

javascript:function f(){return 'success'} f();void(0);

How do i capture the return value, when i type this in an address bar?


Solution

  • What about something like this:

    javascript:function f(){return 42}; var r = f(); alert("The result is " + r); void(0);