Problem in iehover.js

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manishakoi
    New Member
    • Mar 2008
    • 2

    Problem in iehover.js

    HI all

    This script is giving me an error getElementById is not an object or null

    [CODE=javascript]
    sfHover = function() {
    // Support the standard nav without a class of nav.
    var el = document.getEle mentById("nav") ;
    if(!/\bnav\b/.test(el.classN ame) && el.tagName == "UL")
    setHover(el);

    // Find all unordered lists.
    var ieNavs = document.getEle mentsByTagName( 'ul');
    for(i=0; i<ieNavs.length ; i++) {
    var ul = ieNavs[i];
    // If they have a class of nav add the menu hover.
    if(/\bnav\b/.test(ul.classN ame))
    setHover(ul);
    }

    }

    function setHover(nav) {
    var ieULs = nav.getElements ByTagName('ul') ;
    if (navigator.appV ersion.substr(2 2,3)!="5.0") {
    // IE script to cover <select> elements with <iframe>s
    for (j=0; j<ieULs.length ; j++) {
    var ieMat=document. createElement(' iframe');
    if(document.loc ation.protocol == "https:")
    ieMat.src="//0";
    else if(window.opera != "undefined" )
    ieMat.src="";
    else
    ieMat.src="java script:false";
    ieMat.scrolling ="no";
    ieMat.frameBord er="0";
    ieMat.style.wid th=ieULs[j].offsetWidth+"p x";
    ieMat.style.hei ght=ieULs[j].offsetHeight+" px";
    ieMat.style.zIn dex="-1";
    ieULs[j].insertBefore(i eMat, ieULs[j].childNodes[0]);
    ieULs[j].style.zIndex=" 101";
    }
    // IE script to change class on mouseover
    var ieLIs = nav.getElements ByTagName('li') ;
    for (var i=0; i<ieLIs.length ; i++) if (ieLIs[i]) {
    // Add a sfhover class to the li.
    ieLIs[i].onmouseover=fu nction() {
    if(!/\bsfhover\b/.test(this.clas sName))
    this.className+ =" sfhover";
    }
    ieLIs[i].onmouseout=fun ction() {
    if(!this.contai ns(event.toElem ent))
    {
    this.className= this.className. replace(' sfhover', '');
    }
    }
    }
    } else {
    // IE 5.0 doesn't support iframes so hide the select statements on hover and show on mouse out.
    // IE script to change class on mouseover
    var ieLIs = document.getEle mentById('nav') .getElementsByT agName('li');
    for (var i=0; i<ieLIs.length ; i++) if (ieLIs[i]) {
    ieLIs[i].onmouseover=fu nction() {this.className +=" sfhover";hideSe lects();}
    ieLIs[i].onmouseout=fun ction() {this.className =this.className .replace(' sfhover', '');showSelects ()}
    }
    }
    }

    // If IE 5.0 hide and show the select statements.
    function hideSelects(){
    var oSelects=docume nt.getElementsB yTagName("selec t");
    for(var i=0;i<oSelects. length;i++)
    oSelects[i].className+=" hide";
    }

    function showSelects(){
    var oSelects=docume nt.getElementsB yTagName("selec t");
    for(var i=0;i<oSelects. length;i++)
    oSelects[i].className=oSel ects[i].className.repl ace(" hide","");
    }

    // Run this only for IE.
    if (window.attachE vent) window.attachEv ent('onload', sfHover);
    // end[/CODE]

    Can anyone pls help me?

    manisha.
    Last edited by gits; Apr 3 '08, 01:34 PM. Reason: added code tags
  • manishakoi
    New Member
    • Mar 2008
    • 2

    #2
    I have called .js in a page in this way


    <script type="text/javascript" language="JavaS cript1.2">
    <!--#include virtual="iehove r.js"-->

    Can someone pls help me


    bye Manisha.
    Last edited by gits; Apr 3 '08, 01:40 PM. Reason: deleted unrelated bunch of css - MOD

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      This is a question better asked of the javascript people, not .NET.
      I will move the thread for you.
      MODERATOR

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        do you have an element with the id = "nav" in your page where the hover should work?

        btw: the css is not needed here at the moment and it is too much code to read through ... please just the code that is related to the problem ... so i've deleted the posted css for now to clean up the thread a bit ... please wait with posting the css until you are asked specifically for it

        kind regards

        Comment

        Working...