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()
1 Answer
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';">
<script>tag just enter your website like this "example.com?func=doSomething" to see it in action.