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.

+3


source to share


4 answers


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.

0


source


If you load it into an iframe, I think you could somehow wait for a specific element to be present and then execute your code.



+1


source


If the link changes the current location of the window, you cannot execute your scripts after the external page has started loading.

0


source


You can not.

Walking the path is putting the site in an iframe on your page. Then report your message in your onload event. And, of course, your address on the address bar will not change.

0


source







All Articles