Click to See Complete Forum and Search --> : browser detection and redirection not working . . . help!!


seanpaul
07-16-2003, 02:41 PM
I have a script that checks to see your browser is above Navigator 6.0 or IE 5, if so, you are directed to the proper page, if not you are directed to an update page.


But the code redirects me to the update page even though I am using Netscape 7.0

Here's the code


<head>
<title>The auto detect browser script</title>
</head>
<html>
<script language="JavaScript">


var browser=navigator.appName;
var version=navigator.appVersion;

// Load page according to browser
function loadPage() {
// find which browser it is
if (browser.indexOf("Netscape") >= 0) {
// find which version
if (version.indexOf("1.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("2.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("3.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("4.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("5.") >= 0) {
window.location="upgrade.html";
}
else {
window.location="SIMC2/HTML/index.html";
}
}

// find which browser it is
if (browser.indexOf("Microsoft") >= 0) {
// find which version
if (version.indexOf("1.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("1.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("3.") >= 0) {
window.location="upgrade.html";
}
else if (version.indexOf("4.") >= 0) {
window.location="upgrade.html";
}
else {
window.location="SIMC2/HTML/index.html";
}
}
}
// stop hiding -->
</script>


<body onLoad="loadPage();">
SIMC ::: checking browser type . . .
</body>
</head>
</html>


and what is ">="? Does that mena greater than or equal to? Maybe that's where the problem is?

thanks

Khalid Ali
07-16-2003, 05:33 PM
what exactly is not working it seem to work on my machine

win2ksp3 mozilla1.4/IE6

seanpaul
07-16-2003, 05:43 PM
Browsing with Netscape 7.0 I should be sent to "SIMC2/HTML/index.html" but I get sent to "upgrade.html"


It is supposed to send people with Netscape 6 and above or IE 5 and above to "SIMC2/HTML/index.html"

And the code should send people with lesser browsers to the upgrade page.

What Am I doing wrong?

Are you sure it works on your computer?


Thanks

pyro
07-16-2003, 05:47 PM
That's because navigator.appVersion returns 5.0 (and in IE6, it will return 4.0). You will want to parse navigator.userAgent instead...

seanpaul
07-16-2003, 06:02 PM
So you said


That's because navigator.appVersion returns 5.0 (and in IE6, it will return 4.0). You will want to parse navigator.userAgent instead...

you mean that navigator.appVersion for Netscape 6 returns 5.0. So does that mean Netscape 7.0 would return 6.0? I am using Netscape 7. If the navigator.appVersion returns one less than its actual number, I should be transfered to the HTML site and not the upgrade page.

How do I pars the navigator.userAgent? and InternetExplorer.userAgent?

Sorry I'm a javascript newbie. Any help is greatly appreciated.

Even you want to show me some tutorials on th4e subject. I've been trying to figure this out for days.

Thanks

thanks

pyro
07-16-2003, 06:15 PM
No, what I mean is that browsers above version 5 will return 5.0...

You might want to take a look at http://javascript.internet.com/user-details/browser-version2.html, though these don't tend to work all that well cross browser...