如何知道是否窗QUOT;负载"事件已经被解雇 [英] how to know if window "load" event was fired already

查看:205
本文介绍了如何知道是否窗QUOT;负载"事件已经被解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个JavaScript脚本。
这个脚本可能会被异步加载(AMD格式)。

I'm writing a Javascript script. This script will probably be loaded asynchronously (AMD format).

在这个脚本,我想要做什么重要的,直到window.load事件被解雇了。
所以,我听窗口load事件。

In this script, I'd like to do nothing important until the window.load event was fired. So I listen to the window "load" event.

但是,如果脚本window.load事件发生后加载中...我怎么能知道window.load已经解雇了?

But if the script is loaded after window.load event... how can I know window.load was already fired ?

当然,我不希望任何其他脚本添加的东西(他们都是异步加载,问题是相同的):)

And of course I don't want to add something in any other scripts (they are all loaded async, the problem is the same) :)

编辑:

想象一下,没有JavaScript的HTML文档中它。

Imagine an HTML doc with no Javascript in it at all.

比别人在这个文档中插入一个标签,而这个script标签加载我的JavaScript文件。

Than someone insert in this doc a tag, and this script tag loads my Javascript file.

这将执行我的脚本。

这怎么脚本就可以知道,如果window.load已经被开除了?

How this script can know if window.load was already fired ?

没有jQuery的,在HTML文档没有任何脚本我之前。

No jQuery, not any script in the HTML doc before mine.

是否有可能知道?

我找到了window.document.readystate财产。此属性是文档准备好了的事件我GESS,不为窗口中的负荷。
有什么窗load事件相似?

I found the window.document.readystate property. This property is for document "ready" event I gess, not for window "load". Is there anything similar for window "load" event ?

推荐答案

最简单的解决办法可能是检查 document.readyState =='完成',见<一href=\"http://www.w3schools.com/jsref/prop_doc_readystate.asp\">http://www.w3schools.com/jsref/prop_doc_readystate.asp

The easiest solution might be checking for document.readyState == 'complete', see http://www.w3schools.com/jsref/prop_doc_readystate.asp

这篇关于如何知道是否窗QUOT;负载&QUOT;事件已经被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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