By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

Netscape 7

P: n/a
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
in*****@stadmek.no

Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Ingmund Sjåstad wrote:
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

--
David Dorward http://david.us-lot.org/
Redesign in progress: http://stone.thecoreworlds.net/
Microsoft announces IE is dead (so upgrade):
http://minutillo.com/steve/weblog/20...ces-ie-is-dead
Jul 20 '05 #2

P: n/a
Lasse Reichstein Nielsen wrote:
"Ingmund Sjåstad" <in*****@sjaastad.no> writes:

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

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


Jul 20 '05 #3

P: n/a
Chris Sharman <ch***********@sorry.nospam> writes:
Lasse Reichstein Nielsen wrote:
if (document.getElemenetById) { elem=document.getElementById(elemName);}
Spotted the deliberate mis^take !


Yes, very good. And it was ofcourse deliberate. Surely. Absolutely!
Untested code!


*cough*

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
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>
Jul 20 '05 #5

P: n/a
"Ingmund Sjåstad" <in*****@sjaastad.no> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

P: n/a
DU
Ingmund Sjåstad wrote:
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
in*****@stadmek.no



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-deve...upgrade_2.html

Updating DHTML Web Pages
http://devedge.netscape.com/viewsour...tml-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
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #7

P: 1
<html>
<head>
<title>Your title here</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name = "GENERATOR" Content = "ScrypTik V1.13">
<script type = "text/javascript" language = "Javascript">
<!-- Hide from older browsers;
function checkElement(getValue)
{
if(getValue == "MARC")
{
document.getElementById("td1").style.visibility="h idden";
document.getElementById("td2").style.visibility="h idden";
document.inputForm.HardwareType.value = "";
}
else if(getValue == "SONY")
{
document.getElementById("td1").style.visibility="v isible";
document.getElementById("td2").style.visibility="v isible";
}
}

// end hide -->
</script>
</head>
<body>
<!-- Insert HTML here -->
<FORM NAME="inputForm">
<TABLE border="2" >
<TR bgcolor="#FFFFFF" onMouseOut="this.bgColor='#FFFFFF';">
<TD>Node Type:</TD>
<TD>
<select name=nodeType onchange= "checkElement(this.value);">
<option value=" "> </option>
<option value="SONY">SONY</option>
<option value="MARC" > MARC</option>
<option value="RANI"> RANI</option>
</select>
</TD>
<TD><FONT color=blue>
Alias Name:
</FONT></TD>
<TD>
<input type=text name="aliasName" value="DOM5" size=25 maxlength=40>
</TD>
</TR>
<TR bgcolor="#FFFFFF" onMouseOut="this.bgColor='#FFFFFF';">
<TD id="td1">Hardware Type:</TD>
<TD id="td2">
<select name=HardwareType>
<option value=" " > </option>
<option value="SONY1" > SONY1</option>
<option value="SONY2" > SONY2</option>
</select>

</TD>
<TD><FONT color=blue>
IP Address:
</FONT></TD>
<TD>
<input type=text name="ipAddress" value="101.199.111.115" size=25 maxlength=40>
</TD>
</TR>
<TR bgcolor="#FFFFFF" onMouseOut="this.bgColor='#FFFFFF';">
<TD>
Managed:
</TD>
<TD>
<select name=managed>
<option value=""> </option>
<option value="true"> True</option>
<option value="false"> False</option>
</select>
</TD>
</TR>
</TABLE>
</body>
</html>

its working fine in IE and Netscape 8.1 but not working in Netscape 4.72, can anyone help me out........ plzzzzzzzzzz
Mar 1 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.