[Javascript] Redirect based on browser

Sanghamitra sanghamitra.das at itreya.com
Mon Dec 2 22:36:10 CST 2002


> I want to redirect users to two different versions of a site depending on
> if they have a browser
> version >4.0 or <4.0. I've tried writing a couple of scripts but they
> didn't work very well so I
> wonder if any of you would happen to have a script already?


Hi Johansson


Can u try this
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera")
== -1));

var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));


now you can chk by
if(is_ie4up)
{
 //write the code for version greater then 4
}
else
{
 //write the code for version less then and equal to 4
}

Regards
Sanghamitra




More information about the Javascript mailing list