简体   繁体   English

是否可以使用网站的网址在网站上运行javascript函数?

[英]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 假设我们有一个名为example.com的网站

In this website we have a single button which when clicked runs a javascript function let's say myFunction() 在这个网站上我们有一个按钮,点击它时运行一个javascript函数让我们说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? 是否可以从firefox的url栏创建一个http请求,这样当这个http请求完成时,按钮也会被点击?

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

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. 一旦URL加载, myFunction就会执行,但是除非使用某种糟糕的服务器端逻辑,否则你无法告诉页面在加载之后执行一些任意的JavaScript而没有页面知道它。

Nope, that's not possible. 不,那是不可能的。

You can't append JS in a url. 你不能在一个网址中附加JS。 You can however use JS instead of a url, so javascript:myFunction() 但是你可以使用JS 而不是 url,所以javascript:myFunction()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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