...

View Full Version : JS Browser Detection and Redirect not working in NS4?



OO7girl
07-09-2004, 07:15 PM
Hello again,

I am using a Javascript redirect to (I think) take users of 4.x browsers and redirect them to a separate page than users of higher-version browsers. I can't seem to get NS 4.79 (which, as I mentioned in my other thread toady, I have to support for some dumb reason) to go the appropriate page (todayinhistoryjava.html). I feel kind of dumb asking this, but because it's 4.70 and not plain old 4.0, does the below JS not quality NS 4.79 as a version 4 browser? If so, how should I modify my code to get the redirect to trap all users of 4.x browsers between versions 4.0 and 5.0?

Here is the code:

<html>
<head>
<SCRIPT language="JavaScript">
<!--
var browserVer=parseInt(navigator.appVersion);
if (browserVer >= 4)
{
window.location="mainpage.html";
}
else
{
window.location="todayinhistoryjava.html";
}
//-->
</SCRIPT>

</head>
<body>

Thanks!

Amanda

jamescover
07-09-2004, 07:36 PM
Hi:

if (document.layers) {

}

shortcut :D


-james

OO7girl
07-09-2004, 07:55 PM
Hi James,

Wouldn't this redirect ALL Netscape users to my "todayinhistoryjava.html" page? Or would it only redirect users whose Netscape version supports STRICTLY layers? (Not sure what version Netscape started supporting iframes....)

OO7girl
07-09-2004, 08:15 PM
Nevermind - tested it and it works great! Thanks!

jamescover
07-09-2004, 10:27 PM
Wouldn't this redirect ALL Netscape users to my "todayinhistoryjava.html" page? Or would it only redirect users whose Netscape version supports STRICTLY layers? (Not sure what version Netscape started supporting iframes....)


Hi:

Sorry it took me so long to respond....

Yeah, I use it myself on my own site. I'm not aware of any problems with doing this. NS6 & IE6+ are DOM browsers...they should all use document.getElementByID. Anyway, I don't keep up with the DOM stuff, 'cause i always code for backwards compatibility...to me, this means, if it works in NN & IE 4, it will work in newer versions as well.. at least, I haven't encountered any problems yet...

Glad it worked for you.



-james

Vincent Puglia
07-09-2004, 10:43 PM
Hi 007,

As james showed you, you should always test for browser features rather than what is written in the navigator object

if you ever have to test for all browsers, this is the order to do it in -- unless you specifically intend to cripple IE5+ and group it in with IE4

if (document.getElementById)
{
\\ all version 5+ browsers (including IE5+, which uses document.all)
}
else if(document.all)
{
\\ ie4 only
}
else if (document.layers)
{
\\ nn4 only
}
else
{
non-div/layering browsers -- version (-4)
}


Vinny



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum