Results 1 to 3 of 3

Thread: add triger to window.onload = function()

  1. #1
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question add triger to window.onload = function()

    Hello all,

    I have in the past been loading a .js file at the bottom of the page to perfom a function on my menu format and layout, however i have been cleaning up my code lately and have been moving alot of functions to "window.onload = function()"

    My question is this: Can someone help me out with the best way to add the code below to the window.onload = function() { } of my .js file that i load at the top of the page.... I have been playing with this for weeks, however i think i am too close to it and can't seem to find where i am going wrong.

    Code:
    function addEvent(obj, evType, fn){ 
     if (obj.addEventListener){ 
       obj.addEventListener(evType, fn, true); 
       return true; 
     } else if (obj.attachEvent){ 
       var r = obj.attachEvent("on"+evType, fn); 
       return r; 
     } else { 
       return false; 
     } 
    }
    
    if (document.getElementById('left_menu')?true:false != false) {
    var list = document.getElementById("left_menu").getElementsByTagName("ul");
    	for(i = 1; i < list.length; i++){
    		if(String(list[i].parentNode.nodeName).toLowerCase() == 'li') {
    			addEvent(list[i].parentNode, 'click', doIT);
    		}
    	}
    }
    
    if (document.getElementById('left_menu'||'top_nav')?true:false != false) {
    document.write("<style> div#left_menu ul ul { display:none; } </style>");
    var theLink = document.links;
      for (var l=0; l < theLink.length; l++)
        if (location.href == theLink[l]||location.href == theLink[l]+'#') { 
    		theLink[l].id = 'selected'; 
    
    		var subLink = theLink[l].parentNode.parentNode.parentNode;
    		var subMenu = theLink[l].parentNode.parentNode;
    
    			if (String(subLink.nodeName).toLowerCase() == 'li') {
    				subLink.id = 'selected';
    				subMenu.id = 'selected';
    			} 
    	}
    }
    
    function doIT() {
    	if (document.attachEvent) {	
    	var theEl = window.event.srcElement.parentNode; }
    	else { var theEl = this; }
    	u=theEl.getElementsByTagName("ul")[0];
    	u.style.display=(u.style.display=='none'||u.style.display=='')?'block':'none';
    }
    Any and all help/suggestions appreciated!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There isn't a single occurrence of 'onload' in your code snippet.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    Quote Originally Posted by jscheuer1
    There isn't a single occurrence of 'onload' in your code snippet.
    Hi John,

    Your right bacause currently i am loading this at the bottom of a page like this...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="includes/style.css" type="text/css">
    <script language="JavaScript" type="text/javascript" src="includes/pageLib.js" ></script>
    </head>
    
    <body>
    content stuff here
    </body>
    <script language="JavaScript" type="text/javascript" src="includes/bpageLib.js" ></script>
    </html>
    So the code above in currently in the bpageLib.js and i am also loading at the top of the page pageLib.js that has a window.onload = function() { } area in it that i am loading other things in also... so i want to modify the bpageLib.js code so that i can remove the need to use that and add some updated code to the window.onload = function() are of the pageLib.js file that gets loaded at the top of the page.

    Hope this makes sense.

    Darren

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •