onmouseover hide/show description block: cross Browser problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aotash
    New Member
    • Feb 2008
    • 1

    onmouseover hide/show description block: cross Browser problem

    This javascript shows and hides description (like alt in image tag). It works in IE but not in Mozilla, what is wrong please help:

    [CODE=javascript]<SCRIPT LANGUAGE="JavaS cript">

    // ############## SIMPLE BROWSER SNIFFER
    if (document.layer s) {navigator.fami ly = "nn4"}
    if (document.all) {navigator.fami ly = "ie4"}
    if (window.navigat or.userAgent.to LowerCase().mat ch("gecko")) {navigator.fami ly = "gecko"}

    // ######### popup text
    descarray = new Array(
    "This site has some of the greatest scripts around!"
    );

    overdiv="0";
    // ######### CREATES POP UP BOXES
    function popLayer(a){
    if(!descarray[a]){descarray[a]="<font color=red>This popup (#"+a+") isn't setup correctly - needs description</font>";}
    if (navigator.fami ly == "gecko") {pad="0"; bord="1 bordercolor=bla ck";}
    else {pad="1"; bord="0";}
    desc = "<table cellspacing=0 cellpadding="+p ad+" border="+bord+" bgcolor=000000> <tr><td>\n"
    +"<table cellspacing=0 cellpadding=3 border=0 width=100%><tr> <td bgcolor=ffffdd> <center><font size=-1>\n"
    +descarray[a]
    +"\n</td></tr></table>\n"
    +"</td></tr></table>";
    if(navigator.fa mily =="nn4") {
    document.object 1.document.writ e(desc);
    document.object 1.document.clos e();
    document.object 1.left=x+15;
    document.object 1.top=y-5;
    }
    else if(navigator.fa mily =="ie4"){
    object1.innerHT ML=desc;
    object1.style.p ixelLeft=x+15;
    object1.style.p ixelTop=y-5;
    }
    else if(navigator.fa mily =="gecko"){
    document.getEle mentById("objec t1").innerHTML= desc;
    document.getEle mentById("objec t1").style.left =x+15;
    document.getEle mentById("objec t1").style.top= y-5;
    }
    }
    function hideLayer(){
    if (overdiv == "0") {
    if(navigator.fa mily =="nn4") {eval(document. object1.top="-500");}
    else if(navigator.fa mily =="ie4"){object 1.innerHTML=""; }
    else if(navigator.fa mily =="gecko") {document.getEl ementById("obje ct1").style.top ="-500";}
    }
    }

    // ######## TRACKS MOUSE POSITION FOR POPUP PLACEMENT
    var isNav = (navigator.appN ame.indexOf("Ne tscape") !=-1);
    function handlerMM(e){
    x = (isNav) ? e.pageX : event.clientX + document.body.s crollLeft;
    y = (isNav) ? e.pageY : event.clientY + document.body.s crollTop;
    }
    if (isNav){documen t.captureEvents (Event.MOUSEMOV E);}
    document.onmous emove = handlerMM;
    // End -->
    </script>[/CODE]

    =============== =============== ============
    and body:

    [HTML]<div id="object1" style="position :absolute; background-color:FFFFDD;co lor:black;borde r-color:black;bor der-width:20; visibility:show ; left:25px; top:-100px; z-index:+1" onmouseover="ov erdiv=1;" onmouseout="ove rdiv=0; setTimeout('hid eLayer()',1000) ">
    pop up description layer
    </div>

    <a href="#" onMouseOver="po pLayer(0)" onMouseOut="hid eLayer()"><font size=-1 face=arial><b>T HE JavaScript Source</b></font></a>

    [/HTML]thanks.
    Last edited by acoder; Feb 14 '08, 10:54 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    The code uses browser detection - it would be better using object/feature detection, but anyway...

    Firefox/Mozilla requires you to give units, e.g. "px" for the position properties (top, left, etc.)

    Comment

    Working...