Skip to content
Advertisement

Call Javascript function from URL/address bar

Is it possible to call a javascript function from the URL? I am basically trying to leverage JS methods in a page I don’t have access to the source.

Something like: http://www.example.com/mypage.aspx?javascript:printHelloWorld()

I know if you put javascript:alert("Hello World"); into the address bar it will work.

I suspect the answer to this is no but, just wondered if there was a way to do it.

Advertisement

Answer

There isn’t from a hyperlink, no. Not unless the page has script inside specifically for this and it’s checking for some parameter….but for your question, no, there’s no built-in support in browsers for this.

There are however bookmarklets you can bookmark to quickly run JavaScript functions from your address bar; not sure if that meets your needs, but it’s as close as it gets.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement