Browser Redirection Based on Browser and Version

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
palmere
Forum Newbie
Posts: 17
Joined: Fri Mar 19, 2004 5:33 pm

Browser Redirection Based on Browser and Version

Post 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
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
palmere
Forum Newbie
Posts: 17
Joined: Fri Mar 19, 2004 5:33 pm

Post by palmere »

Seems like there should be some scripts out there that do this, an y that come to mind?
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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
palmere
Forum Newbie
Posts: 17
Joined: Fri Mar 19, 2004 5:33 pm

Post by palmere »

Thanks much. I'll let you know how it works out.
Post Reply