Forum Moderators: open

Message Too Old, No Replies

Simple IE window.onload alternative?

         

JAB Creations

10:25 am on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So window.onload doesn't work for squat in IE6...

I have a PHP file that renders (and is served as) the JavaScript which based on conditions (detected serverside) determine which functions are loaded in to the onload function...so if a function isn't needed then PHP won't echo that function name in to the master function. The master function is loaded via window.onload.

Anyway what is the simplest way or alternative to window.onload for IE without any other browsers to be considered for any possible issues? I know this sounds cheap but conditional comments allow it. ;)

- John

lavazza

12:12 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



Apart from having to edit the body tag of every page... what's wrong with <body onLoad="myOnLoad();">... it works, I think, on all browsers/platforms

JAB Creations

12:36 pm on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've tried that and IE 6 refuses to behave. Where do we go from here?

- John

JavaScript

function start() {
init28();
target();
init28ie();
}

XHTML

<body onload="start();">

lavazza

1:36 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



Debug time?

Comment out ALL of the code in
init28();
target();
init28ie();

and simply have an alert in each function saying (for e.g.)

function init28(){
alert('init28 has fired');
/* all the other code commented out
...
...
*/
}

That will only take a few minutes and there's a high chance it will reveal if/where there is a bug

Bernard Marx

4:23 pm on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So window.onload doesn't work for squat in IE6...

I agree. It's highly unlikely, John. I've never had a problem, and if this were the case, the whole scripting world would know about it by now.

The most common problem with assiging onload event is conflicts with others. Do you have another script that assigns a function to onload (presumeably aftwerards)?

It may be time to try attachEvent/adEventListener instead.