window.onload,body onload和document.onreadystatechange
2012-12-06 23:51
501 查看
我们经常使用 window.onload 来处理页面,当页面加载完成做一些事情。但这个 window.onload 是页面全部加载完成,甚至包括图片
1. window.onload = function(){}
2. window.onload = functionName; // [color=red]注意:没有括号
3. IE:
window.attachEvent("onload",functionName);
FF:
window.addEventListener(); // 参数怎么写我忘了, 请自己搜索
body onload="init();"事件是等doucment加载完成再加载相应的脚本
document.onreadstatechange()是指当对象状态变更时触发脚本
<script type="text/javascript">
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// create the "page loaded" message
var text = document.createTextNode("Page loaded!");
var message = document.getElementById("message");
message.appendChild(text);
};
/* for Mozilla */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, null);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script defer src=ie_onload.js><"+"/script>");
/*@end @*/
/* for other browsers */
window.onload = init;
</script>
<p id="message"></p>
示例
<script for=window event=onload>
function inint(){
alert("文档加载完成")
}
</script>
<script language="Javascript">
function document.onreadystatechange()
{
DoLayout();
window.onresize = DoLayout;
Composition.document.open()
Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");
Composition.document.close()
Composition.document.designMode="On"
}
</script>
这两种加载脚本的方式只针对IE游览器才有效
<script type="text/javascript">
function init(){
alert("页面加载完毕!");
}
window.onload=init;
</script>
<html>
<body onload="init()">
</body>
</html>
上面两种方式任何游览器都支持
1. window.onload = function(){}
2. window.onload = functionName; // [color=red]注意:没有括号
3. IE:
window.attachEvent("onload",functionName);
FF:
window.addEventListener(); // 参数怎么写我忘了, 请自己搜索
body onload="init();"事件是等doucment加载完成再加载相应的脚本
document.onreadstatechange()是指当对象状态变更时触发脚本
<script type="text/javascript">
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// create the "page loaded" message
var text = document.createTextNode("Page loaded!");
var message = document.getElementById("message");
message.appendChild(text);
};
/* for Mozilla */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, null);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script defer src=ie_onload.js><"+"/script>");
/*@end @*/
/* for other browsers */
window.onload = init;
</script>
<p id="message"></p>
示例
<script for=window event=onload>
function inint(){
alert("文档加载完成")
}
</script>
<script language="Javascript">
function document.onreadystatechange()
{
DoLayout();
window.onresize = DoLayout;
Composition.document.open()
Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");
Composition.document.close()
Composition.document.designMode="On"
}
</script>
这两种加载脚本的方式只针对IE游览器才有效
<script type="text/javascript">
function init(){
alert("页面加载完毕!");
}
window.onload=init;
</script>
<html>
<body onload="init()">
</body>
</html>
上面两种方式任何游览器都支持
相关文章推荐
- window.onload,body onload和document.onreadystatechange
- window.onload,body onload和document.onreadystatechange
- window.onload,body onload,document.onreadystatechange
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang 分类: C1_HTML/JS/JQUERY 2014-08-06 16:47 558人阅读 评论(0) 收藏
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang
- window.onload,&lt;body onload=&quot;function()&quot;&gt;, document.onreadystatechange, httpRequest.onreadystatechang
- js中 onreadystatechange 和 onload的区别
- document.onreadystatechange事件的用法分析 判断页面加载后再执行脚本
- document.onreadystatechange的认识
- 使用 document.onreadystatechange()来判断页面加载完
- document.onreadystatechange()来判断页面加载完
- document.readyState和xmlhttp.onreadystatechange
- document.onreadystatechange的认识
- document.onreadystatechange事件的用法
- document.onreadystatechange事件的用法
- js控制过场动画,setTimeout和clearTimeout的用法以及document.onreadystatechange判断页面是否加载结束
- 使用 document.onreadystatechange()来判断页面加载完