[thelist] Browser Detect with JavaScript
Michael Collins
mcollins206 at home.com
Fri Dec 1 12:18:05 CST 2000
OK, I am sure many of you have your own way and reasons for detecting
browser type and version using JavaScript. There are plenty of
references for existing scripts that are available but none do
exactly what I want so I ma making my own. I wanted to share this
script and ask if anyone sees an improvement on the way I am trying
to pull this off.
My concept is to use this browser detection only to warn people who
have a browser less than what I consider standard but not prevent
them from trying anyhow. Bascially if I detect something that is not
at least of a certain version than I tell them to download a new
version. I am targeting browsers that will allow decent support of
CSS, support for JavaScript 1.2 (though I know IE has its own
quirkiness in its use of JScript), and in general HTML 4.0.
What I considered approved browsers for these purposes are for Mac
and Windows Netscape 4.7+ and 4.08 (is allowed since this is
navigator) and Netscape 6+. IE should be at least 5 on a Mac and 4.5
on Windows. And for Opera I understand that life began at 3.6. Do you
concur?
I think though that for CSS I have to extend the minor restriction
for Netscape to 4.72 is that the case? For Mac and Windows? I am not
as familiar with Netscape's history on Windows, is Netscape 4.08 for
Windows the "Navigator" version and equivalent to 4.72 (as is the
case on the Mac)?
Here is my script in case anyone is interested:
function brwcheck() {
var agt=navigator.userAgent.toLowerCase();
var is_win=((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1));
var is_mac=(agt.indexOf("mac")!=-1);
var is_op=(agt.indexOf("opera") !=-1);
var is_ie=(is_op==false && agt.indexOf("msie") !=-1);
var is_nav=(is_op==false && ((agt.indexOf("mozilla")!=-1) &&
(agt.indexOf("spoofer")==-1) && (agt.indexOf("compatible")==-1)));
if (is_op==true) { var
is_minor=parseFloat(agt.substring(agt.indexOf('opera')+5,(agt.length-1)));}
else {
if(is_ie==true) { var
is_minor=parseFloat(agt.substring(agt.indexOf('msie')+4,(agt.indexOf('msie')+11)));}
else{var is_minor=parseFloat(navigator.appVersion);}
}
var is_major=parseInt(is_minor);
var resultck=false;
if (is_mac) {if (((is_nav==true) && (is_minor >=4.7)) ||
((is_nav==true) && (is_minor==4.08)) || ((is_ie==true) &&
(is_major >=5))) {resultck=true;}}
else {if (((is_nav==true) && (is_minor >=4.7)) ||
((is_nav==true) && (is_minor==4.08)) || ((is_ie==true) &&
(is_minor >=4.5)) || ((is_op==true) && (is_minor >=3.6)))
{resultck=true;}}
if(resultck==false){
document.write('<P> <br><font size="4"
face="Verdana,Arial,Helvetica,sans-serif"
color="#CC0000"><b><br>Please check that you are using a supported
Web browser!\r</b></font><font size="3"
face="Verdana,Arial,Helvetica,sans-serif" color="#CC0000"><br>This
includes:\r<br>Macintosh: IE 5.0+, Netscape 4.7+ and 6+<br>Windows:
IE 4.5+, Netscape 4.7+ and 6+\r<p>You can download the latest
versions for free at the following locations:\r<br><a
href="http://home.netscape.com/download/">Netscape</a>\r<br><a
href="http://www.microsoft.com/windows/ie/download/ie55.htm">Internet
Explorer Windows 5.5</a>\r<br><a
href="http://www.microsoft.com/mac/products/ie/">Internet Explorer
Mac 5</a>\r<br><a
href="http://www.opera.com/download/index.html">Opera</a></font><P>');
}
}
Michael
--
==> Michael Collins
--> Kuwago Web Services
--> Seattle, WA, USA
--> mcollins at nwlink.com
==> www.lassodev.com
More information about the thelist
mailing list