View Full Version : window.onload doesn't work in IE, but works on FF

07-29-2010, 06:41 AM
I met a confusion about window.onload()

in my index page, here is the code:
<script language = "JavaScript">

<div id="main"></div>

js file:

Main = function()
Main.loadHome = function()


<script language="JavaScript" type="text/javascript">

Here is the problem
it works in FF, but seems window.onload didn't call in IE, which makes me confused.

07-29-2010, 10:13 AM
anyone help me?

07-29-2010, 11:13 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<meta name="author" content="Dean Edwards"/>
<!-- keeping code tidy!! -->
<meta name="copyright" content="&copy; copyright 2005, Dean Edwards"/>
#message {
background-color: red;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
<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");

/* for Mozilla */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script defer src=ie_onload.js><"+"/script>");
/*@end @*/

/* for other browsers */
window.onload = init;

<p id="message"></p>
<script type="text/javascript">
// create a unique image source so that this page works with continued testing
var src = "http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg?" + Number(new Date);
document.write("<img src=" + src + " height=240 width=300>");

This works fine in all the browsers
Thanks & Regards