SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question attatched JavaScript canceled out the main JS

    the site in question

    This problem is for IE 6 only! Strangely it works in IE 7 and FF.

    I have 2 JavaScripts on the frontpage of this site both doing 2 totally different things!
    One is for the drop down menu and the other is for speech bubbles. I put the JavaScript for the speech bubbles in a seperate file and attatched it.
    Code:
    <script type="text/javascript" src="tooltip.js"></script>
    The JS for the drop down menu is in the index file
    Code:
    <script type="text/javascript"><!--//--><![CDATA[//><!--
    
    startList = function() {
    	if (document.all&&document.getElementById) {
    		navRoot = document.getElementById("nav");
    		for (i=0; i<navRoot.childNodes.length; i++) {
    			node = navRoot.childNodes[i];
    			if (node.nodeName=="LI") {
    				node.onmouseover=function() {
    					this.className+=" over";
    				}
    				node.onmouseout=function() {
    					this.className=this.className.replace(" over", "");
    				}
    			}
    		}
    	}
    }
    window.onload=startList;
    
    //--><!]]></script>
    If I put the attatched JS below the drop down menu then the drop down menu works but the speech bubbles dont work. Same thing happens if I switch them so the JS for the drop down menu is under the attatched JS then the speech bubbles work and the drop down menu doesnt.

    The only browser thats giving me a problem is IE 6 now.. Any ideas people please?

    Merry Christmas and happy new year!

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The best idea is to put all your script text outside of the html,
    in script elements with src attributes,
    like you did with the tooltip script.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This doesnt solve the problem tho. Ive attatched the drop down menu JS now (nav.js).
    Code:
    <script type="text/javascript" src="tooltip.js"></script>
    <script type="text/javascript" src="nav.js"></script>

    Now ive made the nav is attatched it doesnt work in FF or IE 7. When you roll over VIEW a speech bubble it should appear but only the drop down menu works!?

    I think its some sort of parent / child or primary / slave thing going on here.. Any ideas please?

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that when you set window.onload a second time it overrides the first time you set it.

    You either need to use a set of event manipulation functions, like the ones by Dean Edwards or do something like this:
    Code:
    window.onload = function() {
      makeNiceTitles();
      startList();
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added this code at the end of the tooltips.js and it hasnt fixed it..
    Code:
    window.onload = function() {
      makeNiceTitles();
      startList();
    }
    I read Dead Edwards but its hard to understand because im very new to JS! Dean Edwards said try this:
    Code:
    <body onload="doSomething()">
    Im not sure what to do..

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shtoom View Post
    I added this code at the end of the tooltips.js and it hasnt fixed it..
    Code:
    window.onload = function() {
      makeNiceTitles();
      startList();
    }
    You need to remove the line where you set window.onload in the other file.

    Quote Originally Posted by shtoom View Post
    I read Dead Edwards but its hard to understand because im very new to JS! Dean Edwards said try this:
    Code:
    <body onload="doSomething()">
    Dean put that in his post to say that his script includes some code to keep that from preventing window.onload from working. It's bad practice to use inline events, especially on <body>.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  7. #7
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright excellent thanks it works!!!!!
    Merry Christmas and happy new year!!!!!


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
  •