469,927 Members | 1,731 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

onmouseover hide/show description block: cross Browser problem

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

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2.  
  3. // ############## SIMPLE BROWSER SNIFFER
  4. if (document.layers) {navigator.family = "nn4"}
  5. if (document.all) {navigator.family = "ie4"}
  6. if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}
  7.  
  8. // ######### popup text
  9. descarray = new Array(
  10. "This site has some of the greatest scripts around!"
  11. );
  12.  
  13. overdiv="0";
  14. // ######### CREATES POP UP BOXES
  15. function popLayer(a){
  16. if(!descarray[a]){descarray[a]="<font color=red>This popup (#"+a+") isn't setup correctly - needs description</font>";}
  17. if (navigator.family == "gecko") {pad="0"; bord="1 bordercolor=black";}
  18. else {pad="1"; bord="0";}
  19. desc = "<table cellspacing=0 cellpadding="+pad+" border="+bord+" bgcolor=000000><tr><td>\n"
  20. +"<table cellspacing=0 cellpadding=3 border=0 width=100%><tr><td bgcolor=ffffdd><center><font size=-1>\n"
  21. +descarray[a]
  22. +"\n</td></tr></table>\n"
  23. +"</td></tr></table>";
  24. if(navigator.family =="nn4") {
  25. document.object1.document.write(desc);
  26. document.object1.document.close();
  27. document.object1.left=x+15;
  28. document.object1.top=y-5;
  29. }
  30. else if(navigator.family =="ie4"){
  31. object1.innerHTML=desc;
  32. object1.style.pixelLeft=x+15;
  33. object1.style.pixelTop=y-5;
  34. }
  35. else if(navigator.family =="gecko"){
  36. document.getElementById("object1").innerHTML=desc;
  37. document.getElementById("object1").style.left=x+15;
  38. document.getElementById("object1").style.top=y-5;
  39. }
  40. }
  41. function hideLayer(){
  42. if (overdiv == "0") {
  43. if(navigator.family =="nn4") {eval(document.object1.top="-500");}
  44. else if(navigator.family =="ie4"){object1.innerHTML="";}
  45. else if(navigator.family =="gecko") {document.getElementById("object1").style.top="-500";}
  46. }
  47. }
  48.  
  49. // ######## TRACKS MOUSE POSITION FOR POPUP PLACEMENT
  50. var isNav = (navigator.appName.indexOf("Netscape") !=-1);
  51. function handlerMM(e){
  52. x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
  53. y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
  54. }
  55. if (isNav){document.captureEvents(Event.MOUSEMOVE);}
  56. document.onmousemove = handlerMM;
  57. // End -->
  58. </script>
==========================================
and body:

[HTML]<div id="object1" style="position:absolute; background-color:FFFFDD;color:black;border-color:black;border-width:20; visibility:show; left:25px; top:-100px; z-index:+1" onmouseover="overdiv=1;" onmouseout="overdiv=0; setTimeout('hideLayer()',1000)">
pop up description layer
</div>

<a href="#" onMouseOver="popLayer(0)" onMouseOut="hideLayer()"><font size=-1 face=arial><b>THE JavaScript Source</b></font></a>

[/HTML]thanks.
Feb 14 '08 #1
1 3262
acoder
16,027 Expert Mod 8TB
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.)
Feb 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Tim | last post: by
2 posts views Thread by steven | last post: by
19 posts views Thread by dmiller23462 | last post: by
3 posts views Thread by alex | last post: by
1 post views Thread by Ciuin | last post: by
5 posts views Thread by jkershner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.