简体   繁体   中英

is it possible to run a javascript function on a website by using the url of the website?

Suppose that we have a website called example.com

In this website we have a single button which when clicked runs a javascript function let's say myFunction()

Is it possible to create an http request from the url bar of firefox so that when this http request is finished, the button would be clicked as well?

For instance, it would be good if I could include this url to the url bar of my browser

example.com + javascript:myFunction()

which would run the function after loading the page without having me to click on the button

however this does not work for me.

thank you in advance

You can use window.onload :

window.onload = function() {
    myFunction();
}

as soon as the URL has loaded myFunction will execute, but unless some kind of bad server side logic is used, you can not tell a page to execute some arbitrary JavaScript after it has loaded without the page knowing of it.

Nope, that's not possible.

You can't append JS in a url. You can however use JS instead of a url, so javascript:myFunction()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM