can I register two events onload in IE

Discussion in 'JavaScript' started by jawednazarali, Feb 21, 2007.

  1. #1
    I am using two open source scripts one for Menu (fsmenu) and other for DragnDrop (wz_dragdrop). they both register their events to onload. it is working fine in firefox and mozilla but when I try to run the page in IE it only registers one binding i.e. registered last.

    Is there any way I can run both the script on IE. or any workarounds to register two events on load.

    thanks in advance.
     
    jawednazarali, Feb 21, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Link to your page or code?
     
    nico_swd, Feb 21, 2007 IP
  3. jawednazarali

    jawednazarali Guest

    Messages:
    254
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    find the attached zip file to view what i have been doing.

    thanks
     

    Attached Files:

    jawednazarali, Feb 21, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    You can try with something like this:

    
    
    attachOnloadEvent(myOnloadFunc1);
    
    // attach func function to window onload event (crossbrowser compatible)
    function attachOnloadEvent(func) 
    {
    	if(typeof window.addEventListener != 'undefined') {
    		// moz, saf1.2, ow5b6.1
    		window.addEventListener('load', func, false);
    	} else if (typeof document.addEventListener != 'undefined') {
    		// MSN/OSX, op7.50, saf1.2, ow5b6.1
    		document.addEventListener('load', func, false);
    	} else if (typeof window.attachEvent != 'undefined') {
    		// ie5.0w, ie5.5w, ie6w
    		window.attachEvent('onload', func);
    	} else {
    		// all other browsers
    		if (typeof window.onload == 'function') 
    		{
    			var oldonload = onload;
    			window.onload = function() {
    				oldonload();
    				func();
    			};
    		} 
    		else 
    		{
    			window.onload = func;
    		}
    	}
    }
    
    
    Code (markup):
     
    ajsa52, Feb 21, 2007 IP
  5. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Create one function that calls your two functions and call it in onload.

    It seems pretty cut and dry to me.
     
    noppid, Feb 21, 2007 IP
  6. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Yep, noppid is right. Its a quit easy and logical solution.
     
    designcode, Feb 21, 2007 IP