本文讨论Window的load,document的start、end、idle等事件之间的加载顺序。以及JQuery(document).ready()
1,document.ready和Window.load
document.ready事件指的是网页dom(主体,不含src,link,和图片之类)的对象,加载完成。
window.load 指的是所有的对象,包含dom,包含src,link和图片对象。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
console.log("document loaded");
});
$(window).load(function() {
console.log("window loaded");
});
</script>
</head>
<body>
<iframe src="http://www.baidu.com"></iframe>
</body>
</html>
上述代码,先出现document.loaded ,后出现window loaded
可以参见:http://stackoverflow.com/questions/588040/window-onload-vs-document-onload
- By default, it is fired when the entire page loads, including its content (images, css, scripts, etc.)
- In some browsers it now takes over the roll of document.onload and fires when the DOM is ready as well.
document.onload
- It is called when the DOM is ready which can be prior to images and other external content is loaded.