We help IT Professionals succeed at work.

window.onload in IE6 - does it work?

Lady_M asked
Last Modified: 2013-12-08

I've asked this question in a roundabout way in a couple of other threads but I'm not getting to the bottom of it. It seems pretty straightforward but the info on the web gets pretty complex.
So I thought I'd keep it simple: can you use 'window.onload' in IE6?

I want to use it in the head of a page to initialise 3 functions that are in an external js file.

I can't get it working.  So, if not, what do you do instead?

Watch Question


Hi thanks for getting back to me.  I've read one of those articles before, but it does my head in.  I don't get what the point of that init() is and where you put your function initiations.  Do you?
you write init() and include it as a js include.  the contents of the function are basically what you wanted to do inside the window.onload event.  the idea here is that you just call a custom function, rather than using window.onload.


Hi again.

But it says that the init file should just contain one line:

Are you saying that isn't the case and actually that init function should list my three function calls?  That makes sense.  

If so, what would the exact syntax in that init() function be please?
init (){
initiate function 1(arg, arg);
initiate function 2 ();
initiate function 3();
i think you're thinking about this the wrong way.  let's step back.

you wanted to do something using window.onload.  so, you were likely trying something like this:


then, the body of callMyFunction is whatever JavaScript you wanted to do when the window loaded.

since window.onload is not valid in IE6, you have to put a function call in the HTML somewhere, so that when the page loads, it will do something.  so, you do that <script> include that includes the javascript code containing the init() function.  then, in the init function, you do whatever you were going to do inside the callMyFunction.

does that make sense?

the example i sent you doesn't know what you were trying to do once you did window.onload.  it was just trying to show an alternative method of calling some function once the page loads.  after that, it's up to each person to decide what to do in the function.
Unlock this solution and get a sample of our free trial.
(No credit card required)


Hi jmanGJHS97
Thanks, but I'm afraid I really don't understand.  V. confused.
Could you do me a favour and spell it out to me if you have time please? ie: "put this in the html head, put this in the external js and put this in the init.js page".  
You can't assume I know the syntax either.

So my html head looks like this:
<script type="text/javascript" language="javascript" src="/global/scripts/global.js"></script>
window.onload = function() { rolloverButtons(); rolloverMenuL2 (); populateBox (1.html', null); };

And my /global.js looks like this:
// JavaScript Document
<script language="JavaScript" type="text/javascript" defer="defer">
//1.  Rollover  Menu:  Show list on hover.
rolloverButtons = function() {    
alert ("rollover buttons");
      var sfEls = document.getElementById('navbuttons').getElementsByTagName('LI');    
      for (var i=0; i<sfEls.length; i++) {        
            sfEls[i].onmouseover=function() {            
            this.className+=" sfhover";        
            sfEls[i].onmouseout=function() {            
                  this.className=this.className.replace(new RegExp(" sfhover\\b"), "");        

//2. Rollover Top Nav Menu:  Show second level of drop-down menu to IE by assigning class to #header #banner ul#navL2 li
rolloverMenuL2 = function() {  
alert ("rollover menu");

      var sfEls = document.getElementById('navL2').getElementsByTagName('LI');
      for (var i=0; i<sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
                  this.className+=" over";
            sfEls[i].onmouseout=function() {
                  this.className=this.className.replace(new RegExp(" over\\b"), "");

//3 Post file into box, uses prototype.js which should be in same directory.
function populatebox (serverPage, obj){      
alert ("populate box");

var objID = "boxtext";  
   new Ajax.Updater(objID, serverPage);

//change tab color
  if(obj != null)
   var links = document.getElementById('box').getElementsByTagName('A');
    for (var i=0; i<links.length; i++) {
      if (links[i].className=='highlighted' && links[i] != obj)  

i would say the easiest way to do this is to just take the 3 function calls you have in your window.onload function and put them into the body onload event, like this:

<body onload="rolloverButtons(); rolloverMenuL2 (); populateBox (1.html', null);">

then, just delete this:

window.onload = function() { rolloverButtons(); rolloverMenuL2 (); populateBox (1.html', null); };

that should do the same thing for you.  all the example was doing is putting those 3 function calls into another function, but you could just call them in the body tag, like i show here.
i'm not sure what this is:


there is a trailing single quote, which will cause an error.  also, you can't name an element with a number.

if you have a text box like this:

<input type="text" id="myTextBox" value="" />

then you can call your populateBox like this:

populateBox(document.getElementById('myTextBox).innerHTML, null);

but, this question is about the window.onload event, not debugging your javascript.  that stuff is better suited for another question in EE.


Yes, I really just want to get the initialisation of the external functions working, that's all.  I will worry about code problems later.  (incidentally, the file isn't really called 1.html, that's just for convenience here).

But if you can give me some more help on initialising the 3 functions please, if you have time, that would be much appreciated as that is the major issue at the moment.

what exactly is not working?  i provided an example that will call the 3 functions when the page loads.  that seemed to me to be the crux of your question.


Hi jmanGJHS97, yes you did, sorry I missed a couple of your replies. I see what you're doing now thanks.
Not a problem.  Glad it's working for you.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.