PDA

View Full Version : browser/version detection and redirection


brent
07-15-2002, 06:13 AM
i am doing some things that only seem to work in IE6...is it possible to have the HTML detect what browser and version is being used, and if its not IE6 it will redirect them to a different place???

thanks

premshree
07-15-2002, 07:13 AM
Yes it is possible:


<script language="JavaScript">
function redir()
{
var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1;
if(!ie)
{
location.href="somefile.html";
}
}
</script>

<body onLoad="redir()">


:thumbsup:

WA
07-15-2002, 07:17 AM
Here's a more "delicate" script that redirects depending on a variety of browsers: http://www.dynamicdrive.com/dynamicindex9/bredirect.htm

elson
12-30-2002, 10:45 PM
Hello!

The answers posted here before don't solve this question. It's easy to do it between NS, Opera and IE. But, how to detect and redirect between IE 6 and IE 5?

I've the same problem, and another way to suggest how to solve it.

It's easy to detect the brower type and version with the script below:

<script>

/*Displaying a user's browser type script
By JavaScript Abstration (javascriptkit.com)
Over 200+ free scripts here!
*/

if (document.all)
var version=/MSIE \d+.\d+/

if (!document.all)
document.write("You are using "+navigator.appName+" "+navigator.userAgent)
else
document.write("You are using "+navigator.appName+" "+navigator.appVersion.match(version))

</script>

This script displays the complete browser type for both, IE 6 and IE 5. So, how to get this answer and use it to redirect to a specific page?



:confused:

beetle
12-30-2002, 10:50 PM
Here (http://www.webreference.com/tools/browser/javascript.html) is a pretty complete sniffer that does object sniffing, as well as specific version sniffing as well.

elson
12-31-2002, 12:04 AM
Tks, Beetle

I do some cuts and adaptations in the script, on that page you suggested, and now it is functional:

<head>
<script LANGUAGE="JavaScript">
<!-- hide JavaScript from non-JavaScript browsers
// This script is a simplified adaptation from the
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan
// see http://www.webreference.com/ for more information

var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";
var is_ie = ((iePos!=-1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5 = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") !=-1));
var is_ie5_5up =(is_ie && is_minor >= 5.5);
var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);
// -->
</script>
</head>

<body>

<script LANGUAGE="JavaScript">
<!--
if (is_minor!=6)
window.location.replace('somewhere.htm');
//--></script>


my best wishes and happy new year,

:thumbsup:

Graeme Hackston
12-31-2002, 12:13 AM
If you only want IE6 you can cut your code down alot by only sniffing for it.

elson
01-01-2003, 02:59 PM
Yes, Graeme, surely.

Sweeping more the script:


<script LANGUAGE="JavaScript">
<!-- hide JavaScript from non-JavaScript browsers
// This script is a simplified adaptation from the
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan
// see http://www.webreference.com/ for more information
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_ie = ((iePos!=-1));
var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);
if (is_minor!=6)
window.location.replace('croncal.htm');
// -->
</script>

Tks.