Automatically execute javascript function when loading external website
So, I want to have a link to site x (which I am not a developer) that does some javascript function automatically after clicking it. EG.
javascript:window.location="http://www.google.com"; alert("Hello");
Performs a warning function before loading a page that is not needed.
Does anyone else know how this can be achieved?
Thank.
source to share
You cannot do this.
Doing this poses a security risk (XSS) and is therefore prohibited by almost all browsers!
Worst scenarios to think about if you have this control:
-
Script to grab the username / password of a user and send it to you, additionally calling Url.
-
May play a role in frivolous tracking / spam.
EDIT:
This can only be done with user interaction.
For example,
-
You can ask the user to drag the link to the bookmark toolbar, and the link should contain:
<a href="javascript:alert('click');">Test Click</a>
-
And then on whatever page the user goes to, whenever he clicks the bookmark (link) button, an alert (or whatever Script) happens.
source to share