Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting IE using jQuery

Tags:

$(window).load(function () {
   if($.browser.msie && $.browser.version=="6.0") {
     // do stuff
   }
});

Just realized that $.browser has been depreciated in 1.3. What is the new method for detecting IE, specially IE6.

like image 800
eozzy Avatar asked Dec 22 '09 04:12

eozzy


People also ask

How do I know if my browser is IE?

To detect whether the current browser is Internet Explorer, you can make use of the navigator. userAgent property. The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.

How do I know if I have IE 11?

Press the Alt key (next to the Spacebar) on the keyboard to open a menu bar. Click Help and select About Internet Explorer. The IE version is displayed in the pop-up window.

How do I know what browser I am using JavaScript?

To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.


2 Answers

The jQuery documentation for jQuery.browser shows the following warning. (Emphasis is mine.)

Because $.browser uses navigator.userAgent to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. Instead of relying on $.browser it's better to use libraries like Modernizr.

The documentation page also says:

This property was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

Even jQuery.support, which was suggested from the old documentation has the following warning. (Emphasis is mine.)

A collection of properties that represent the presence of different browser features or bugs. Intended for jQuery's internal use; specific properties may be removed when they are no longer needed internally to improve page startup performance. For your own project's feature-detection needs, we strongly recommend the use of an external library such as Modernizr instead of dependency on properties in jQuery.support.

The previous documentation for jQuery.support reported the following properties and values.

  • $.support.boxmodel is false in IE 6, and 7.
  • $.support.cssFloat is false for IE 6, 7 and 8; it is true in IE 9.
  • $.support.leadingWhitespace is false for IE 6, 7, and 8.
  • $.support.objectAll is currently false for IE 6, 7, and 8.
like image 96
apaderno Avatar answered Sep 24 '22 13:09

apaderno


hot from the documentation: We recommend against using this property, please try to use feature detection instead (see jQuery.support).

like image 42
just somebody Avatar answered Sep 22 '22 13:09

just somebody