Netscape compatibility

S

Simon Wigzell

I pulled some 3rd party code off the internet that makes a span visible on
mouseover of a link. It works fine in IE, doesn't work for Netscape, it goes
into "Unknown", see it here :
http://www.studioapriori.com/cavendishSimon/divtest.htm How can I make it
work for all browsers? (Within reason of course!)

<html>
<head>
<style type="text/css"><!--
..absolute { position:absolute; visibility:hidden; }
//--></style>
</head>
<body>
<script language="JavaScript"><!--
function showOffset(object,x,y) {
if (document.layers && document.layers[object]) {
document.layers[object].left += x;
document.layers[object].top += y;
document.layers[object].visibility = 'visible';
}
else if (document.all) {
document.all[object].style.posLeft = document.all[object].offsetLeft
+ x;
document.all[object].style.posTop = document.all[object].offsetTop +
y;
document.all[object].style.visibility = 'visible';
}
else {
alert("Unknown");
}
}

function hideOffset(object,x,y) {
if (document.layers && document.layers[object]) {
document.layers[object].visibility = 'hidden';
document.layers[object].left -= x;
document.layers[object].top -= y;
}
else if (document.all) {
document.all[object].style.visibility = 'hidden';
document.all[object].style.posLeft -= x;
document.all[object].style.posTop -= y;
}
}
//--></script>
<span id="myLayer6" class="absolute"><img src="img/privacy_policy_roll.gif"
width="219" height="150"></span>

<a href="nextpage.htm" onMouseover="showOffset('myLayer6',100,100)"
onMouseout="hideOffset('myLayer6',100,100)">example 6</a>
</body>
</html>
 
S

Simon Wigzell

snip

It's okay, I found the answer, still, which browser will activate the first
if statement block? I might as well do a proper test - opera? mozilla?

function showOffset(object,x,y) {
if (document.layers && document.layers[object]) {/* ??? */
document.layers[object].left = x;
document.layers[object].top = y;
document.layers[object].visibility = 'visible';
}
else if (document.all) { /* IE */
document.all[object].style.posLeft = x;
document.all[object].style.posTop = y;
document.all[object].style.visibility = 'visible';
}
else if (document.getElementById){ /* Netscape */
document.getElementById(object).style.left = x;
document.getElementById(object).style.top = y;
document.getElementById(object).style.visibility = 'visible';
}
else {
alert("Unknown");
}
}
 
R

Ron

Simon said:
snip

It's okay, I found the answer, still, which browser will activate the first
if statement block? I might as well do a proper test - opera? mozilla?

function showOffset(object,x,y) {
if (document.layers && document.layers[object]) {/* ??? */
document.layers[object].left = x;
document.layers[object].top = y;
document.layers[object].visibility = 'visible';
}
else if (document.all) { /* IE */
document.all[object].style.posLeft = x;
document.all[object].style.posTop = y;
document.all[object].style.visibility = 'visible';
}
else if (document.getElementById){ /* Netscape */
document.getElementById(object).style.left = x;
document.getElementById(object).style.top = y;
document.getElementById(object).style.visibility = 'visible';
}
else {
alert("Unknown");
}
}
I believe document.layers is a deprecated NN4 interface.
document.getElementById is present in all contemporary
standards-compliant browsers (Opera, Mozilla and other Gecko-based) and
IE5.5+.
 
L

Lasse Reichstein Nielsen

Simon Wigzell said:
It's okay, I found the answer, still, which browser will activate the first
if statement block? I might as well do a proper test - opera? mozilla?

function showOffset(object,x,y) {
if (document.layers && document.layers[object]) {/* ??? */

I only know one browser apart from Netscape 4 that has
document.layers, and that is OmniWeb. As far as I remember having been
told, it is not functional, so the second half of the test is likely
to fail.
document.layers[object].left = x;
document.layers[object].top = y;
document.layers[object].visibility = 'visible';
}
else if (document.all) { /* IE */

That is not correct. There are browsers apart from IE that understand
document.all.
document.all[object].style.posLeft = x;

Since posLeft is not a standard CSS property (so I assume it's
specific to IE), it is likely that non-IE browsers that has
document.all will fail this line. Change to:
document.all[object].style.left = x + "px";
document.all[object].style.posTop = y;
ditto

document.all[object].style.visibility = 'visible';
}
else if (document.getElementById){ /* Netscape */

This is also not the case. There are many, many browsers that support
document.getElementById. Some of these will also support document.all,
but I doubt that Gecko based browsers are the only ones with only
document.gEBI.
document.getElementById(object).style.left = x;

Gecko based browsers (which is what I assume you mean by "Netscape")
in standards compliant mode will ignore this line, because you lack
the unit. Change to:

document.getElementById(object).style.left = x + "px";

If your page is not triggering standards compliant mode, you should
change it. Quirks mode is for compatability with old and badly written
pages, and not something one should author new pages for.


Generally, I would test for document.gEBI first instead of last. Any
new browser will understand that. Should it also support document.all
or even document.layers, it should not be mistaken for an old Netscape
or IE.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top