简体   繁体   English

在网址上运行JavaScript函数? google.com?javascript:(func())

[英]running JavaScript function on url? google.com?javascript:(func())

I would like to run javascript function after link load. 我想在链接加载后运行javascript函数。 Link is for example google and I would like to run function after load, without pressing any bookmarks etc. Is it possible to make a link like 链接是例如谷歌,我想在加载后运行功能,而无需按下任何书签等。是否可以使链接像

http://google.com?javascript:(function (){}(something here);)

Thanks for your answers 谢谢你的回答

这是不可能的,因为如果是这样的话,那么XSS攻击可能就在每个链接的拐角处。

Nope, URLs just don't support this. 不,URL只是不支持此功能。 There are bookmarklets the user can use once the page loads, but nothing you can automatically run as part of a URL. 页面加载后,用户可以使用小书签 ,但是没有任何内容可以作为URL的一部分自动运行。

That is impossible. 那是不可能的。 You cannot control the code on other pages (this would be a huge security problem). 您无法控制其他页面上的代码(这将是一个巨大的安全问题)。

As everyone else has noted, you cannot run a Javascript function that way. 正如其他所有人都指出的那样,您不能以这种方式运行Javascript函数。

What is it that you're hoping to accomplish with your javascript? 您希望使用javascript完成什么? Perhaps there is another way to achieve your end result? 也许还有另一种方法可以达到最终结果?

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

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