Problems Redirecting to a CSS Page Once NN6 & NN7 are Detected

  • Thread starter that guy over there
  • Start date
T

that guy over there

Ugh, am pulling my hair out over this one...

I want to be able to format a page slightly differently depending on
whether or not a user is visiting the site using either Netscape 6 or
7.

That bit I seem to have sorted out; my problem is getting the &*$%#
link function to work from a document.write statement.

For example, the following code correctly differentiates between the
two Netscapes (at least on Windows):

<html>
<head>
<script>
// netscape browsers
var is_nn6 = (navigator.product == 'Gecko') &&
(!window.find)?true:false;
var is_nn7 = (navigator.product == 'Gecko') &&
(window.find)?true:false;
</script>
</head>
<body>
Netscape browsers<br>
<script>
document.write("NN6:" + is_nn6 + "<BR>");
document.write("NN7:" + is_nn7 + "<BR>");
</script>
</body>
</body>
</html>

But if I try adding the following code to the header of the page in
order to redirect the page to point to separate .css files, I only get
a page saying "Netscape browsers", so it is somehow blowing out the
valid true or false values I get from the ternary statements.

if (is_nn6)
{document.write("<link rel=\"stylesheet\"
href=\"nn6.css\"/>"};
else if (is_nn7)
{document.write("<link rel=\"stylesheet\"
href=\"nn7.css\"/>"};

What the heck am I doing wrong/am missing? Probably something silly
and obvious, but I can't figure out what... Ugh. Help much
appreciated.
 
M

Martin Honnen

that said:
Ugh, am pulling my hair out over this one...

I want to be able to format a page slightly differently depending on
whether or not a user is visiting the site using either Netscape 6 or
7.

That bit I seem to have sorted out; my problem is getting the &*$%#
link function to work from a document.write statement.

For example, the following code correctly differentiates between the
two Netscapes (at least on Windows):

<html>
<head>
<script>
// netscape browsers
var is_nn6 = (navigator.product == 'Gecko') &&
(!window.find)?true:false;
var is_nn7 = (navigator.product == 'Gecko') &&
(window.find)?true:false;
</script>
</head>
<body>
Netscape browsers<br>
<script>
document.write("NN6:" + is_nn6 + "<BR>");
document.write("NN7:" + is_nn7 + "<BR>");
</script>
</body>
</body>
</html>

But if I try adding the following code to the header of the page in
order to redirect the page to point to separate .css files, I only get
a page saying "Netscape browsers", so it is somehow blowing out the
valid true or false values I get from the ternary statements.

if (is_nn6)
{document.write("<link rel=\"stylesheet\"
href=\"nn6.css\"/>"};
else if (is_nn7)
{document.write("<link rel=\"stylesheet\"
href=\"nn7.css\"/>"};

What the heck am I doing wrong/am missing? Probably something silly
and obvious, but I can't figure out what... Ugh. Help much
appreciated.

Check the JavaScript console, if the code throws an error it will be
reported there
 
T

that guy over there

Check the JavaScript console, if the code throws an error it will be
reported there

Doh! Was missing a ")" at the end of each line of the document.write
statement. And Venkman lead me right to it, like you suggested. ;-)

Ugh.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top