Page 1 of 1

Browser detection

Posted: Thu Aug 17, 2006 7:49 pm
by alex.barylski
I need a well maintained script/API which I can include in my apps to to determine which browser I'm dealing with???

Anyone know of one?

Posted: Thu Aug 17, 2006 7:50 pm
by feyd
On the PHP side?

get_browser() .. I've posted a purely php version too, viewtopic.php?p=237279#237279

Posted: Thu Aug 17, 2006 8:02 pm
by alex.barylski
This time I actually mean client side...as in Javascript... :)

I can find some with a quick Google search but I was hoping to find one which is well maintained, etc...

Popular and all that jazz...

Posted: Thu Aug 17, 2006 8:06 pm
by feyd
One that can detect down to pretty finite details would be quite large as the database behind get_browser() (and my function) is like several hundred kilobytes. Basic determination is pretty simple and there are many methods to obtain that out there.

Posted: Thu Aug 17, 2006 9:12 pm
by alex.barylski
Something as simple as version and browser type

Primarily:
- IE
- FF
- NS
- OP

Would suffice, as I don't plan on supporting any others... :?

Posted: Fri Aug 18, 2006 12:47 am
by matthijs
Hockey, if I may ask, for what do you need the script?

If it is only for the layout/css I would strongly advice against using a browser detection script. Certainly not javascript. The recommended way is conditional comments to feed IE 5,6 or both their own stylesheet. Only if really necessary. If you need the script for something else I'll shut up..

Posted: Fri Aug 18, 2006 2:15 pm
by christian_phpbeginner
Hockey wrote:Something as simple as version and browser type

Primarily:
- IE
- FF
- NS
- OP

Would suffice, as I don't plan on supporting any others... :?
Hi, give this link a try:
http://www.w3schools.com/js/tryit.asp?f ... js_browser

Firefox browser will be detected as Netscape. You can however detect mozilla by using the navigator.appCode object.

See the detailed code below which I pasted from http://www.w3schools.com/js/tryit.asp?f ... serdetails:

Code: Select all

<script type="text/javascript" language = "javascript">

   function getBrowserSpec() {
      document.write("<p>Browser: ");
      document.write(navigator.appName + "</p>");

      document.write("<p>Browserversion: ");
      document.write(navigator.appVersion + "</p>");

      document.write("<p>Code: ");
      document.write(navigator.appCodeName + "</p>");

      document.write("<p>Platform: ");
      document.write(navigator.platform + "</p>");

      document.write("<p>Cookies enabled: ");
      document.write(navigator.cookieEnabled + "</p>");

      document.write("<p>Browser's user agent header: ");
      document.write(navigator.userAgent + "</p>");

</script>
Not sure if this what you wanted....

Cheers,
Chris

Posted: Fri Aug 18, 2006 2:30 pm
by alex.barylski
matthijs wrote:Hockey, if I may ask, for what do you need the script?

If it is only for the layout/css I would strongly advice against using a browser detection script. Certainly not javascript. The recommended way is conditional comments to feed IE 5,6 or both their own stylesheet. Only if really necessary. If you need the script for something else I'll shut up..
I need it to perform conditional testing inside a javascript :P

So I can adjust it to work on as many browsers as possible...not selecting CSS, etc...

Cheers :)

Posted: Fri Aug 18, 2006 2:59 pm
by matthijs
Ok. I was afraid you were going to use it for css.. :wink:

Well, about javascript. I know Jeremy Keith (of domscripting) is a proponent of Object detection instead of browser detection.
Something like this:

Code: Select all

if (method) {
statements
}
example

Code: Select all

function someFunction() {
  if(document.getElementById) {
   statements using getElementByID
  }
}

Don't know if you thought about that?

Posted: Fri Aug 18, 2006 3:19 pm
by feyd
matthijs wrote:

Code: Select all

function someFunction() {
  if(document.getElementById) {
   statements using getElementByID
  }
}

Don't know if you thought about that?
I prefer that way of determination too. :)

Posted: Tue Sep 05, 2006 4:16 am
by chenggn
The old fashion codes

Code: Select all

var isKHTML = navigator.appVersion.match(/Konqueror|Safari|KHTML/); 
var isOpera = navigator.userAgent.indexOf('Opera') > -1;
var isIE = !isOpera && navigator.userAgent.indexOf('MSIE') > 1;
var isMoz = !isOpera && !isKHTML && navigator.userAgent.indexOf('Mozilla/5.') == 0;