Author Topic: How to detect browser type?  (Read 605 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
How to detect browser type?
« on: September 30, 2010, 01:54:31 AM »
I thought it would be trivial, but it seems it is really problematic and unreliable.

http://renegademinds.com/TipsTricks/DevelopersCorner/HTTP_USER_AGENT/tabid/84/Default.aspx

Any idea how to detect browser type and version (without use of get_browser(); due to performance concerns)? At least I would want a reliable way to detect if the browser is IE6 or not (since it is the only currently existing that causes serious problems).

Offline Winawer

  • Level 6
  • *
  • Posts: 27
  • Reputation: +0/-0
    • View Profile
Re: How to detect browser type?
« Reply #1 on: September 30, 2010, 03:00:38 AM »
What are you trying to do?

For example, you could add an IE6 specific stylesheet with
Code: [Select]
<!--[if IE 6]>
   <link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: How to detect browser type?
« Reply #2 on: September 30, 2010, 05:10:41 AM »
At least I would want a reliable way to detect if the browser is IE6 or not (since it is the only currently existing that causes serious problems).
Come on... IE9 is in beta status now. Personally, my policy is to support last 2 iterations of a browser. 3 is getting yourself in deep with compatibility testing but 4 is just ridiculous.

You know... if the world stops supporting IE6, the users will change their browsers (or the IT staff will be forced to update the office's software to take advantage of newer browsers). If we keep supporting IE6, it will never die.... And I think everyone wants that. ;)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: How to detect browser type?
« Reply #3 on: September 30, 2010, 07:11:16 AM »
At least I would want a reliable way to detect if the browser is IE6 or not (since it is the only currently existing that causes serious problems).
Come on... IE9 is in beta status now. Personally, my policy is to support last 2 iterations of a browser. 3 is getting yourself in deep with compatibility testing but 4 is just ridiculous.
Maybe I want to do this? Making a page that display "upgrade your browser, dude" if it detects IE6? :D

Just making things broken will achieve nothing if the user do not know it is due to outdated browser.

Quote
[if IE 6]
No... The IE6 coverage is not enough to pollute HTML output for all users. Something gentler. Also I would like to make the browser version number a PHP variable so I can switch to crippled layout version (not css but whole different page generation which is more convenient and flexible) or display some warning, redirect to another page, etc.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: How to detect browser type?
« Reply #4 on: September 30, 2010, 07:50:15 AM »
So... instead of supporting the browser (which takes time which could be better spent doing something else) you're spending time which could be better spent doing something else just to tell users of a single browser to upgrade. ;)

This is why you should just "not worry about it." For those browsers. If the site is too broken to use, they'll upgrade when every website starts doing the same thing. If it's not too broken to use... then let them use it. It's not like it took you any extra effort.

I'm usually against turning away potential customers. But, seriously, if they aren't even computer literate enough to know how to install a proper browser then I probably can't trust that they know how to make online purchases either. So, I'm only losing a potential "free-only" account. And one that's dumb enough to still be using IE6 at that. I'm better off without them. ;)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Winawer

  • Level 6
  • *
  • Posts: 27
  • Reputation: +0/-0
    • View Profile
Re: How to detect browser type?
« Reply #5 on: September 30, 2010, 07:53:52 AM »
Quote
[if IE 6]
No... The IE6 coverage is not enough to pollute HTML output for all users. Something gentler. Also I would like to make the browser version number a PHP variable so I can switch to crippled layout version (not css but whole different page generation which is more convenient and flexible) or display some warning, redirect to another page, etc.

In that case, I think HTTP_USER_AGENT is the closest you're going to get.

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: How to detect browser type?
« Reply #6 on: October 01, 2010, 08:08:18 AM »
If it were me I'd use conditional html tags, from what I can tell its the best way to detect which browser your client is using, and hot-writing the body tag means your not adding additional http requests. Recently I've been using http://html5boilerplate.com/ and I must say I am mightily impressed by how it all just works. Within the boilerplate they use the following to detect browser.

Code: [Select]
<!--[if lt IE 7 ]> <body class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <body class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <body class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <body class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <body> <!--<![endif]--

If you wanted to read more into this system checkout http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ I really do think this is the best way to roll.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal