Question

I'm recently looking all my project jquery to the latest version and I hit a road block when I heard that $.browser is deprecated and removed from the latest jquery version

So I decide to use modernizer to achieve the same but I somehow was not able to get the browser object when I run this $.browser on console instead I get undefined

Here is the JSFIDDLE output describing the same

Any thing that I'm doing wrong

Was it helpful?

Solution

Browser detection vs Feature Detection

Or Why is browser sniffing not a recommended practice?

I recomend you some research about Feature Detection, and why it's better than Browser Detection or Browser Sniffing. This article on the jQuery learning center explains both techniques, and why feature detection is better than browser detection.

To summarize, quoting the article I refer:

Browser detection

Browser detection is a method where the browser's User Agent (UA) string is checked for a particular pattern unique to a browser family or version.

Feature detection

Specific feature detection checks if a specific feature is available, instead of developing against a specific browser. This way, developers can write their code for two cases: the browser does support said feature, or the browser does not support said feature.

While Browser detection seems to be an easy solution, there are several problems:

  • Other browsers other than your target may have the same issue. If we target a specific browser for different functionality, we implicitly exclude any browser we did not account for.

  • User Agents are unreliable. User Agents are set by the client browser and are also user-configurable. While the user may change this string, the browser's feature support remains the same.


As said by @Garath on his answer, I recomend you modernizr as feature detection library. You can also take a look at jQuery.support, but the jQuery team does not recommend using it as it's intended for jQuery's internal use.

OTHER TIPS

Using Modernizer you can check if some functionality of HTML5 is available in selected browser. It is not a library to bring back $.browser

If you need to bring back $.browser you can use: https://github.com/gabceb/jquery-browser-plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top