我们经常使用 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> 上面两种方式任何游览器都支持
|