PDA

View Full Version : Browser Detection




Titan85
07-02-2007, 05:51 AM
Hello, I am trying to make a script that will display a popup message if the user is on IE 6. I used to know how to do this, but haven't done it in so long that I forgot. I am assuming that it should look something like this: if (browser detection code = ie6) alert("My text");How do I go about finding what browser is being used? Thanks

codeexploiter
07-02-2007, 07:56 AM
You can use the following function which will return true if the browser is IE 6.


function isExplorer6() {
var appVer = navigator.appVersion;
appVer = appVer.split(';');
if(appVer[1] == ' MSIE 6.0') {
return true;
}
}

Twey
07-02-2007, 08:03 AM
You really shouldn't use browser detection: it's impossible to completely accurately detect the browser without knowing and testing the features of every browser that does or will exist. To detect IE, I suggest conditional comments:<script type="text/javascript">
var ie6 = false;
</script>
<!--[if IE eq 6]>
<script type="text/javascript">
ie6 = true;
</script>
<![endif]-->... but even this should be avoided if possible.You can use the following function which will return true if the browser is IE 6.Unless the browser is using a different UA string, such as Avant or AOL, of course. Then there's spoofing of the UA to consider, possible future modifications to the browser that might change the format of the UA string slightly...

Titan85
07-02-2007, 02:06 PM
Thanks guys, both of your information was helpful.

SayJumner
07-27-2007, 09:34 PM
I want a script that will detect what browser the surfer is using and alert them it is best viewed with browsers and versions i state. is this script the one i want? or can you help me find another better one?

Twey
07-27-2007, 10:03 PM
Please don't do that... there are few "features" of websites that irritate me more. If the site is really unusable in browsers other than the one(s) you've chosen, it's broken. A proper standards-compliant site should work with any browser -- that's the point of standards. If it's still usable but perhaps benefits from features of certain browsers, you might want to make a small note at the bottom of the page that the page has features that will only work in those browsers. There's certainly no need for anything as intrusive as an alert.