Userscript在执行代码技术之前等待页面加载? [英] Userscript to wait for page to load before executing code techniques?

查看:110
本文介绍了Userscript在执行代码技术之前等待页面加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Greasemonkey用户脚本,并希望在页面完全加载时执行特定代码,因为它返回我想要显示的div计数。

I'm writing a Greasemonkey userscript, and want specific code to execute when the page completely finishes loading, since it returns a div count I want displayed.

问题是的,这个特定的页面有时会在所有内容加载之前占用一点。

Problem is, this particular page sometimes take a bit before everything loads.

我试过,记录 $(function(){}); $(window).load(function(){}); 包装器。但是,似乎没有一个对我有用,虽然我可能会错误地应用它们。

I've tried, document $(function() { }); and $(window).load(function(){ }); wrappers. However, none seem to work for me, though I might be applying them wrong.

我能做的最好是使用 setTimeout(function() {},600); 哪个有效,但并不总是可靠。

Best I can do is use a setTimeout(function() { }, 600); which works, though not always reliable.

什么是在Greasemonkey中使用的最佳技术,以确保特定代码将执行当页面加载完毕后?

Whats the best technique to use in Greasemonkey to ensure specific code will execute when page finishes loading?

推荐答案

Greasemonkey(通常)没有jQuery。所以常见的方法是使用

Greasemonkey (usually) doesn't have jQuery. So the common approach is to use

window.addEventListener('load', function() {
    // your code here
}, false);

在你的用户名中

这篇关于Userscript在执行代码技术之前等待页面加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆