正在加载页面并在其上执行 JS...从 JS 书签?
本质上,我试图
- 导航到一个网页,
- 等待该网页加载,
- 执行该页面上的 JS 函数/警报/任何内容
并从单个书签中 。这可能吗?我似乎无法为自己工作,但这可能是因为我个人的失败。
Essentially I'm trying to
- navigate to a webpage
- wait for that webpage to load
- execute a JS function/alert/whatever on that page
all from a single bookmarklet. Is this possible? I can't seem to get onload to work for me, but that may be because of my own personal failings here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现不需要 Greasemonkey 或类似的东西就能做到这一点的最简单方法是编写 JS,以便它检查它是否在适当的页面上,如果不在则转到那里。如果它在页面上,那么它会执行 JS/alert/whatever。您必须使用该小书签两次,但您只需要一个小书签,并且用户进行点击/无论他或她自己做什么可能仍然更快/更容易。所以代码看起来像这样:
The simplest way I found to do this without needing Greasemonkey or something similar is to write your JS so that it checks to see if it is on the appropriate page, and goes there if it isn't. If it is on the page, then it executes the JS/alert/whatever. You have to use the bookmarklet twice, but you just need one bookmarklet, and it may still be quicker/easier the user doing the clicking/whatevering him or herself. So the code would look like this:
您想要安装适用于 Firefox 的 Greasemonkey 扩展程序。 (或 gm4ie 对于 IE,或 greasemetal 适用于 Chrome (PersonalizedWeb 在 Chrome 中也能以更简单的方式工作),greasekit 适用于 Safari,或 user.js for Opera)
Greasemonkey 可以让您做到这一点...在每次页面加载时自动运行脚本(您可以选择它加载的页面/站点)
否则,您将需要在每个页面加载时单击小书签才能运行脚本。
You want to install the Greasemonkey extension for Firefox. (or gm4ie for IE, or greasemetal for Chrome (PersonalizedWeb also works in a much simpler way for Chrome), greasekit for Safari, or user.js for Opera)
Greasemonkey lets you do exactly this... run a script automatically on every page load (you can choose what pages/sites it loads on)
Otherwise you will need to click your bookmarklet on every page load in order to run your script.
鉴于没有更好的解决方案,我想我应该放弃 Opera 本身支持在每个页面加载时运行的用户脚本。从那里,您可以让脚本检查当前 url,并在适当的页面上运行。
请参阅此处获取文档
Given there's no better solution, I thought I'd toss out that Opera natively supports user scripts to run on every page load. From there, you could have the script check the current url, and run if on appropriate page.
See here for documentation
另一种选择是调用window.open(...),并使用窗口对象来操作窗口。也可以通过这种方式导航多个页面。
Another option is to call
window.open(...)
, and use the window object to manipulate the window. It is also possible to navigate multiple pages this way.