Page 1 of 1

Browser Redirection Based on Browser and Version

Posted: Wed Apr 07, 2004 5:03 pm
by palmere
Hey all,
I'm designing a page for a college campus that *still* has some of its public computers running Netscape 3.5... Needless to say, I'm tired of dumbing down the code for the entire page enough to make the version that is displayed on Net 3.5 look decent.

What I want to do is have all relatively recent browsers (IE4+, Netscape4+, and Safari) redirect to a main page - index2.php - while the old browsers Netscape3-, and so on be redirected to a another - index-outdated.php - for a more basic page. I found this script and I've been playing around with it a little to get it to work, but I've been lacking success. Any ideas?

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

var name = navigator.appName;
var vers = navigator.appVersion;
vers = vers.substring(0,1); // or 0,4  could return 4.5 instead of just 4

if (name == "Microsoft Internet Explorer") 
url="msie";
else 
url="netscape";
url += vers + ".html";
window.location=url;   

// End -->
</script>
Thanks.

E

Posted: Wed Apr 07, 2004 6:22 pm
by Unipus
I strongly recommend that you use feature detection instead of browser agent detection, if you're going to use javascript. Better than that, even, would be to use user-agent detection in PHP; that way the redirection is entirely transparent to the user.

Posted: Wed Apr 07, 2004 6:31 pm
by palmere
Seems like there should be some scripts out there that do this, an y that come to mind?

Posted: Thu Apr 08, 2004 1:54 pm
by Unipus
Nope. I honestly couldn't tell you how the hell you detect for v.3 browsers, but I'm sure if you look, W3C can tell you *something* they don't support that v4 do.

[php_man]get_browser[/php_man] is useful for PHP

Posted: Thu Apr 08, 2004 3:41 pm
by palmere
Thanks much. I'll let you know how it works out.