[thelist] Browser Detect with JavaScript

Michael Collins mcollins206 at home.com
Sat Dec 2 11:04:35 CST 2000


At 5:12 PM +1300 12/2/00, Grant wrote:
>Ok I'm not a fan of browser detection scripts. What I think is preferable is
>'object detection' not browser detection.

I have heard this argument before and I do think it makes some sense. 
Not sure why I didn't start out my script thinking that way but 
thanks for the reminder. So basically if a Web browser can pass the 
test of understanding the w3c DOM or at least the IE4 "all" version 
of the DOM then I can consider that browser will be capable of 
displaying my CSS1 site with perhaps only a few problems.

So thus, I could present a warning message to users with my revised script:

function brwcheck() {

   //The default is set to false (incompatible),
   var resultck=false; 

   //then all approved/compatible browsers are set to true
   //DOM1 compliance ns6 and ie5 and anytime soon opera 4+
   if(document.getElementsByTagName){resultck=true;}

   //ie4 all DOM
   if (document.all){resultck=true;}

   if(resultck==false){
     document.write('Please check that you are using a supported Web browser');
   }
}

Then put in document where you want message displayed:
<script language="JavaScript" type="text/javascript">
brwcheck();
</script>

That certaintly simplifies things! And also allows other unknown 
browsers in as long as they conform to the standards.

Just to check, using this will IE 4.5 browsers get the warning?

If I want to also allow Netscape 4.7 and 4.08 (and not any other 
prior versions of Netscape 4) then I could insert the following 
before I do the final check on whether to put up a warning message:

//Allow Netscape 4.7 and 4.08
var agt=navigator.userAgent.toLowerCase();
var is_nav=((agt.indexOf("mozilla")!=-1) && (agt.indexOf("compatible")==-1));
var is_minor=parseFloat(navigator.appVersion);
if((is_nav==true)&&((is_minor>=4.7) || (is_minor==4.08))){resultck=true;}

I will be testing my own site to see if Netscape 4.7 and 4.08 hold up 
with my CSS. I want to support it since there are a lot of users for 
this specific site that have that browser.

Michael
-- 
==> Michael Collins
--> Kuwago Web Services
--> Seattle, WA, USA
--> mcollins at nwlink.com
==> http://www.lassodev.com




More information about the thelist mailing list