Netscape 7

  • Thread starter Ingmund Sjåstad
  • Start date
I

Ingmund Sjåstad

This scipt is working in IE6 but not in Netscape 7. What am I doin wrong?

<script language="JavaScript" type="text/JavaScript">

var ns = false;
var ie = false;

ie = (document.all) ? true : false;
ns = (document.layers) ? true : false


function hideLayer(layerName) {
if (ie){
document.all(layerName).style.visibility="hidden";
document.all(layerName).style.width="16";
document.all(layerName).style.height="16";
} else if (ns) {
document.layers[layerName].visibility = "hide";
document.layers[layerName].width="16";
document.layers[layerName].height="16";
}
}

function showLayer(layerName) {
if (ie){
document.all(layerName).style.visibility="visible";
document.all(layerName).style.width="140";
document.all(layerName).style.height="400";
} else if (ns) {
document.layers[layerName].visibility = "show";
document.layers[layerName].width="140";
document.layers[layerName].height="400";
}
}

</script>


--

___________________________
Best Regards,

Ingmund Sjåstad
(e-mail address removed)
 
D

David Dorward

Ingmund said:
This scipt is working in IE6 but not in Netscape 7. What am I doin wrong?
ie = (document.all) ? true : false;
ns = (document.layers) ? true : false
document.all(layerName).style.width="16";

(1) You are detecting a single feature of IE or NS rather then performing
object detection for every feature you wish to use.

(2) You are using an MSIE specific feature to detect IE and a NS 4.x
specific feature to detect NS.

Modern browsers (NS6+, Mozilla, IE (5+?), Opera etc) use the W3C DOM.
document.getElementById('id_of_element').

(3) You are forgetting the units on your lengths
 
C

Chris Sharman

Lasse said:
You have a script that attempts to detect IE and Netscape 4, and only
in those cases does it do anything. Since Netscape 7 is not IE or
Netscape 4, it does exactly what it is being asked to do: nothing.
Pedantically, I would say that the script works. It just doesn't do
what you expect.

The code isn't very pretty either, with lots of repeated
subexpressions, so here is an alternative: (I dislike using the word
"layer" about something not created with the <layer> tag, so I renamed
the functions too. I consider it artistic license :)

<script type="text/javsscript">
var px="px";
function getStyle(elemName) {
var elem;
if (document.getElemenetById) { elem=document.getElementById(elemName);}

Spotted the deliberate mis^take !
else if (document.all) { elem=document.all[elemName];}
else if (document.layers) { elem=document.layers[elemName]; px="";}
else {return null;}

if (!elem.style) {
return elem;
}
return elem.style;
}

function hideElement(elemName) {
var style=getStyle(elemName);
if (style) {
style.visibility="hidden";
style.width=16+px;
style.height=16+px;
}
}

function showElement(elemName) {
var style=getStyle(elemName);
if (style) {
style.visibility="visible";
style.width=140+px;
style.height=400+px;
}
}

</script>

Untested code!

This is not perfect, there are browsers without document.layers that
don't want "px" after the lengths (e.g., Opera 6). Netscape 7 requires
the "px" in standards mode (and you shouldn't write new pages to Quirks
mode!)

It is not necessary to use "show" and "hide" for Netscape 4, it
understands "visible" and "hidden" fine. It just converts them to
"show" and "hide" internally, so if you read the value back, it will
be the four letter one. (Tested in NS4.08/Win)

/L
 
I

Ingmund Sjåstad

I have now tried this, but it is still not working in Netscape 7.

The whole examplefile:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>JS</title>

</head>

<body bgcolor="#FFFFFF">

<script language="JavaScript" type="text/JavaScript">

var px="px";

function getStyle(elemName) {
var elem;
if (document.getElemenetById) { elem=document.getElementById(elemName);}
else if (document.all) { elem=document.all[elemName];}
else if (document.layers) { elem=document.layers[elemName]; px="";}
else {return null;}

if (!elem.style) {
return elem;
}
return elem.style;
}

function hideElement(elemName) {
var style=getStyle(elemName);
if (style) {
style.visibility="hidden";
style.width=16+px;
style.height=16+px;
}
}

function showElement(elemName) {
var style=getStyle(elemName);
if (style) {
style.visibility="visible";
style.width=140+px;
style.height=400+px;
}
}

</script>

<br>
<br>
<div onMouseOver="showElement('test')" onMouseOut="hideElement('test')">
<a href="">Toggle</a>
</div>

<div id="test" style="position:absolute; z-index:1; left: 200px; top:
200px;">
Toogle this ....
</div>

</body>
</html>
 
L

Lasse Reichstein Nielsen

Ingmund Sjåstad said:
I have now tried this, but it is still not working in Netscape 7.

As someone pointed out, there was a typo in a very significant place:
<script language="JavaScript" type="text/JavaScript">

language="JavaScript" is deprecated!
if (document.getElemenetById) { elem=document.getElementById(elemName);}

should be
if (document.getElementById) { elem=document.getElementById(elemName);}

If you change that, it works in my Mozilla Firebird.

/L
 
D

DU

Ingmund said:
This scipt is working in IE6 but not in Netscape 7. What am I doin wrong?

<script language="JavaScript" type="text/JavaScript">

var ns = false;
var ie = false;

ie = (document.all) ? true : false;
ns = (document.layers) ? true : false


function hideLayer(layerName) {
if (ie){
document.all(layerName).style.visibility="hidden";
document.all(layerName).style.width="16";
document.all(layerName).style.height="16";
} else if (ns) {
document.layers[layerName].visibility = "hide";
document.layers[layerName].width="16";
document.layers[layerName].height="16";
}
}

function showLayer(layerName) {
if (ie){
document.all(layerName).style.visibility="visible";
document.all(layerName).style.width="140";
document.all(layerName).style.height="400";
} else if (ns) {
document.layers[layerName].visibility = "show";
document.layers[layerName].width="140";
document.layers[layerName].height="400";
}
}

</script>


--

___________________________
Best Regards,

Ingmund Sjåstad
(e-mail address removed)

These pages are precisely meeting your NS 4 and NS 7 difficulties.

Using Web Standards in Your Web Pages
http://www.mozilla.org/docs/web-developer/upgrade_2.html

Updating DHTML Web Pages
http://devedge.netscape.com/viewsource/2001/updating-dhtml-web-pages/

W3C markup validator
http://validator.w3.org/

Activating the Right Layout Mode Using the Doctype Declaration
http://www.hut.fi/u/hsivonen/doctype.html

Giving you the fishing techniques/resources/tools you need.

DU
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top