0

I have a link on my page with href="javascript:sayhello()", is it possible to add this function to full url? Somethink like: http://example.com/page.html+javascript:sayhello()

3
  • And what should that do? Load the link and then execute the JavaScript on the subsequent page? Commented Jan 31, 2015 at 21:45
  • Yes, load page and call the function Commented Jan 31, 2015 at 21:48
  • You can use this example code to achieve that, note it will not work in jsfiddle, you have to import it to your website. After pasting that code in a <script> tag just enter your website like this "example.com?func=doSomething" to see it in action. Commented Jan 31, 2015 at 22:00

1 Answer 1

1

No, that's not possible.

The part of the URL before the : says how the rest of the URL should be interpreted. When it starts with http:, it means that the link should make a GET request to an HTTP server, and request the page whose path is named in the rest of the URL. No Javascript is interpreted as part of that.

When it starts with javascript:, it means that instead of downloading a page from a webserver, it should execute the rest of the URL as Javascript, similar to the element having an onclick.

You could, however, write Javascript that redirects to the page:

<a href="javascript:sayhello(); location.href='http://example.com/page.html';">
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.