D
David List
I'm having a problem using different properties of the document object
in the example javascripts in my textbook with browsers that identify
themselves as using the Mozilla engine. One example of these
problems is using document.layers. I have Google'd for examples of how
to use the document object specifically with Mozilla, but I cannot
find anything that explains why my problems occur. Could anyone here
see through the included example and tell me if there is anything
absolutely wrong with this?
It seems to me that the examples in my textbook simplify browser
identification to the point where it doesn't work. Am I right in this?
----------example----------
<html>
<head>
<meta name="keywords" content="">
<meta name="description" content="">
<title>Test-titel</title>
<link rel="stylesheet" href="./style.css">
<script language="javascript">
<!--
var active = 0;
var browser = null;
function Init()
{
browser = new BrowserObj();
}
function BrowserObj()
{
this.navigator = null;
this.explorer = null;
this.other = null;
if((navigator.appName.toLowerCase()).
indexOf("netscape") >= 0)
this.navigator = 1;
else
if((navigator.appName.toLowerCase()).indexOf("explorer") >= 0)
this.explorer = 1;
else
this.other = 1;
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
}
function ChangeLayer(now)
{
if(browser.navigator != null)
{
document.layers["content" + active].visibility = "hide";
document.layers["content" + now].visibility = "show";
}
else
{
var current = document.all("content" + active).style;
var next = document.all("content" + now).style;
current.visibility = "hidden";
next.visibility = "visible";
active = now;
}
}
// -->
</script>
</head>
<body onLoad="Init()">
<div id="menua" style="top: 5; left: 5; visibility: visible;
position: absolute; z-index: 5;">
<p class="SWITCH">
<a href="#" onClick="ChangeLayer(0)">One</a>
<a href="#" onClick="ChangeLayer(1)">Two</a>
<a href="#" onClick="ChangeLayer(2)">Three</a>
</p>
</div>
<div id="content0" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>A test header</h1>
<p>Here is some text</p>
</div>
<div id="content1" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>One more test header</h1>
<p>Some more test</p>
</div>
<div id="content2" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>Yet one more test header</h1>
<p>Yet more text</p>
</div>
</body>
</html>
----------example----------
in the example javascripts in my textbook with browsers that identify
themselves as using the Mozilla engine. One example of these
problems is using document.layers. I have Google'd for examples of how
to use the document object specifically with Mozilla, but I cannot
find anything that explains why my problems occur. Could anyone here
see through the included example and tell me if there is anything
absolutely wrong with this?
It seems to me that the examples in my textbook simplify browser
identification to the point where it doesn't work. Am I right in this?
----------example----------
<html>
<head>
<meta name="keywords" content="">
<meta name="description" content="">
<title>Test-titel</title>
<link rel="stylesheet" href="./style.css">
<script language="javascript">
<!--
var active = 0;
var browser = null;
function Init()
{
browser = new BrowserObj();
}
function BrowserObj()
{
this.navigator = null;
this.explorer = null;
this.other = null;
if((navigator.appName.toLowerCase()).
indexOf("netscape") >= 0)
this.navigator = 1;
else
if((navigator.appName.toLowerCase()).indexOf("explorer") >= 0)
this.explorer = 1;
else
this.other = 1;
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
}
function ChangeLayer(now)
{
if(browser.navigator != null)
{
document.layers["content" + active].visibility = "hide";
document.layers["content" + now].visibility = "show";
}
else
{
var current = document.all("content" + active).style;
var next = document.all("content" + now).style;
current.visibility = "hidden";
next.visibility = "visible";
active = now;
}
}
// -->
</script>
</head>
<body onLoad="Init()">
<div id="menua" style="top: 5; left: 5; visibility: visible;
position: absolute; z-index: 5;">
<p class="SWITCH">
<a href="#" onClick="ChangeLayer(0)">One</a>
<a href="#" onClick="ChangeLayer(1)">Two</a>
<a href="#" onClick="ChangeLayer(2)">Three</a>
</p>
</div>
<div id="content0" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>A test header</h1>
<p>Here is some text</p>
</div>
<div id="content1" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>One more test header</h1>
<p>Some more test</p>
</div>
<div id="content2" style="top: 40; left: 0; visibility: visible;
position: absolute;">
<h1>Yet one more test header</h1>
<p>Yet more text</p>
</div>
</body>
</html>
----------example----------