PDA

View Full Version : JS works only in IE6 not Netscape 7.1


Kal_Torak
05-26-2005, 01:15 AM
I have a javascript that works in IE6 but not in Netscape 7.
It is pretty old code but works fine in IE...


<html>
<head>
<TITLE>menu visibility</title>

<style type="text/css">

.Menu {
position: absolute;
width: 80%;
border: 1px white;
background-color: white;
layer-background-color: white;
top: 100px;
left : 10%;
line-height : 25px;
font-family : Arial;
visibility: hidden;
}
.Mo {
position: absolute;
text-decoration : none;
border: 0px white;
background-color: white;
layer-background-color: white;
top: 100px;
left: 10%;
width: 80%;
font-family : Arial;
visibility: hidden;
}
.hide {
visibility: hidden;
font-family : Arial;
}
</style>
<script>
var mo_lastMenu;
var lastMenu = "null";
if (document.layers) {
visible = 'show'; hidden = 'hide';
}
else if (document.all) {
visible = 'visible'; hidden = 'hidden';
}

function toggle(menu) {
if (document.layers) {
Menu = document.layers[menu];
}
else if (document.all) {
Menu = document.all(menu).style;
}
if (Menu.visibility == visible) {
Menu.visibility = hidden;
}
else {
clean(lastMenu);
Menu.visibility = visible;
}
lastMenu = Menu;
}

function clean(Menu){
if (Menu == "null"){
return;
}
if (Menu.visibility == visible) {
Menu.visibility = hidden;
}
}

function mo_toggle(menu) {
if (document.layers) {
Menu = document.layers[menu];
}
else if (document.all) {
Menu = document.all(menu).style;
}
if (Menu.visibility == visible) {
Menu.visibility = hidden;
}
else {
Menu.visibility = visible;
}
mo_lastMenu = Menu;
}


</script>
</head>

<body bgcolor="White">

<CENTER>
<A href="#" onclick="toggle('clickWeb');return false;" onmouseout="javascript:mo_toggle('mo_web');return false;" onmouseover="javascript:mo_toggle('mo_web');return false;" >
<B><font size="+1" color="purple" face="Arial">Put Mouse Over Here here</A></B></FONT>
</CENTER>


<div id="mo_web" class="Mo">
<FONT SIZE="+2" COLOR="green" face="Arial"><CENTER>
This is what happens!!
</FONT></CENTER>
</div>


<div id="clickWeb" class="Menu">
<FONT SIZE="+2" COLOR="red" face="Arial"><CENTER>
Clicking the link presents these results.
</FONT></CENTER>
</div>

<BR>


</body>
</html>

glenngv
05-26-2005, 04:09 AM
Use document.getElementById. It is supported by modern browsers.
You need to change the order of the object detection to:

if (document.getElementById){

}
else if (document.all){

}
else if (document.layers){

}

You may drop the IE4 and NS4 support and just use the document.getElementById.

Kal_Torak
05-26-2005, 02:29 PM
Ok, thanks, I'll go puzzle over that some then :thumbsup:

Kal_Torak
05-26-2005, 04:43 PM
Ah... Its been awhile since I played with JS. I'm lost.
Could you fix the code and post it?

Kal_Torak
05-30-2005, 01:19 PM
Halp?