有没有什么插件可以让javascript在页面加载之前执行?
好吧,greasemonkey 可以执行用户脚本,但只能在页面完全加载后执行。是否有任何脚本可以获取用户脚本(javascript)并在页面下载任何元素之前执行它。 例如,一旦下载了 HTML 文件,用户脚本就应该执行,这样我就可以阻止下载嵌入元素,如 flash、jpg、js 文件下载
Well, greasemonkey can execute users script but only after the page loads fully. Is there any script that can take user script (javascript) and executes it before the page downlaods any elemts.
for instance, As soon as the HTML file is downloaded, the user script should execute so that i can prevents the download of embedded elements like flash, jpg, js files downloads
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最新版本的 Firefox 中有一个 content-document-global-created 通知,该通知会在页面开始加载。
Jetpack SDK 有一个页面 mods 模块,它使用该通知让您编写类似 Greymonkey 的代码片段。这是一种“可以使 javascript 在页面加载之前执行的插件”。
不过,我不知道您如何通过这样的脚本实现内容阻止。
进行内容拦截的常见方法是通过 nsIContentPolicy,这就是 Adblock 使用的方法。
There's a content-document-global-created notification in the recent versions of Firefox that fires before the page started loading.
Jetpack SDK has a Page mods module that uses that notification to let you write greasemonkey-like snippets. That's kind of an "addon that can make javascript execute before the page loads".
I don't know how you'd implement content blocking via such script, though.
The common way to do content blocking is via nsIContentPolicy, which is what Adblock uses.