检查(从bookmarklet)是否已加载页面? [英] Check (from bookmarklet) whether page is loaded?

查看:74
本文介绍了检查(从bookmarklet)是否已加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写小书签javascript.这里的问题是用户可以在某些页面完成加载之前和之后调用它.我想确保仅在页面加载完成后才运行sript.该怎么做?

I'm writing a bookmarklet javascript. The problem here is that it can be invoked by user before and after some page has finished loading. I want to ensure that the sript is run only after the page has finished loading. How to do that?

推荐答案

检查文档是否已加载的一种方法是检查

One way for checking if document has loaded, is to check the document.readyState property. IE, Firefox 3.6+, Webkit and Opera support it.

if (document.readyState === "complete") {
    // do sth
}

另一件事是,如果要等待文档加载.在这种情况下,您必须听一些事件,例如文档上的DOMContentLoaded,窗口上的加载或文档上的readyStateChange.

Another thing is, if you want to wait for the document to load. In that case you have to listen to some events, like DOMContentLoaded on document, load on window or readyStateChange on document.

这篇关于检查(从bookmarklet)是否已加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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