Skip to main content

Bug Tracker

Side navigation

#1134 closed enhancement (duplicate)

Opened April 19, 2007 07:54AM UTC

Closed April 28, 2007 03:00PM UTC

Last modified June 21, 2007 04:25AM UTC

Better browser type and version detection

Reported by: hobbit Owned by:
Priority: major Milestone: 1.1.3
Component: core Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:
Description

Better browser detection script (not finished).

new function(){
  var
  //When the script run, the html element already exists.
  html=document.getElementsByTagName("html")[0],
  b=navigator.userAgent.toLowerCase(),
  version=
    b.match(/opera.(d+.d+)/) ||
    b.match(/; rv:(d+.d+.d+)/) ||
    b.match(/applewebkit.(d+(.d+)?)/) ||
    b.match(/msie (d.d+)/);

  $.browser.msie      = html.style.filter !== undefined;
  //MozBoxAlign attrib supported since Gecko 1.0.x.
  $.browser.mozilla   = html.style.MozBoxAlign !== undefined;
  //opPhonemes attrib supported since Opera 8.0.
  $.browser.opera     = html.style.opPhonemes !== undefined;
  //$.browser.safari  = ???;
  $.browser.version   = (version.length && version[1]) || null;

  $.boxModel = !$.browser.msie || document.compatMode == "CSS1Compat";

  //I don't know this expression works on Macintosh.
  //$.browser.msie = /*@cc_on true || @*/ false;
}
Attachments (0)
Change History (2)

Changed April 28, 2007 03:00PM UTC by john comment:1

resolution: → duplicate
status: newclosed

This should be mentioned as a follow-up to ticket #1101. It's important to note that doing browser detection (instead of feature detection) is exactly what's needed here. Detecting an obscure browser feature can have future, unintended, consequences.

Changed May 01, 2007 10:26AM UTC by hobbit comment:2

Replying to [comment:1 john]:

And if the user agent string is modified, the jQuery not works correctly. Example the conditional compilation works only in Internet Explorer since version 5.0. This detection is trusty: /*@cc_on true || @*/ false;