Bug Tracker

Ticket #1134 (closed enhancement: duplicate)

Opened 8 years ago

Last modified 8 years ago

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:
Blocking: Blocked by:

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;
}

Change History

comment:1 follow-up: ↓ 2 Changed 8 years ago by john

  • Status changed from new to closed
  • Resolution set to duplicate

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.

comment:2 in reply to: ↑ 1 Changed 8 years ago by hobbit

Replying to 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;
Note: See TracTickets for help on using tickets.