On how jquery removed the browser detection _jquery

Source: Internet
Author: User

Because of the HTML5-related projects, many avant-garde front-end technologies need to consider whether IE is supported. In the past, it was easy to call jquery's jquery.browser to implement it.

If (JQuery.browser.msie) alert ("DIE ie!")

But this convenience has ceased to exist after jquery 1.9. Suddenly feel like lost a most intimate comrades, a I do not leave the development of a good base friend, a I left can not write Cross-browser front-end code good tools. All of a sudden I didn't know what to do.

And then every time I need to consider IE, I will go to Google, How to use the 1.9 version of jquery to detect IE, but most of the answers on StackOverflow told me: jQuery1.9 waste le Jquery.browser, recommended jquery.support, but no one told me why.

I don't know if my brain was caught in the door for half a day, but why was it wasted? Anyway, my goal is very simple, is to detect the current user is not IE, if not ie, then I need to pop-up related information to tell users you are using IE, some features may not be supported so ...

Helpless, so that my code back to the No jquery Stone Age, with the most original plain JavaScript code to detect IE, and about such a method, because there are countless predecessors in the game with IE accumulated a lot of experience, ready-made method has been written more than N, So I'm just going to pick one up and use it. And each use is not the same, the next time you encounter to detect IE, and go to Google one, get another piece of code to achieve the same effect.

But the problem is to feel awkward, in order to detect an IE, you need to specifically for this to have a large section of ugly and page function logic irrelevant code. It feels like installing a cracked software and being bundled with a large number of advertising plug-ins.

With the recent Windows8.1 Hair Department casually concerned about the subsequent IE11, the official actually said the goods will support WEGGL technology! IE11 will support the technology that Microsoft has been spurned by. It's not really that strange. Because IE by the front-end personnel as early as the IE6 began, so many years passed, the developer is not and it co-exist down well.

But IE11 support WebGL with this article of the yarn relationship? is not much of a relationship, but I suddenly realized that before the HTML5 project in Three.js write things can run on IE, at least on the IE11! So the previous detection of IE is very illogical. I head seemed to come out of a golden light, out of a misunderstanding before: really do not need to detect the user is not using IE browser. Our goal is to make the code work. If the current browser supports the features in our code, then it works, if not, then the strike gives a hint.

So I seem to understand why jquery doesn't support Jquery.browser in 1.9, and instead gives the support API, and when I search for "detect ie" questions again, I also have a voice that advises Modernizr.js ( A JavaScript library that detects browser support for HTML5,CSS3.

Because the detection of IE itself is unscientific. Although some HTML5 features IE are not supported now, it is constantly being updated, so it does not mean that later versions are not supported. So if the code still has a very straightforward code specifically for IE, it seems rather unscientific. As mentioned above in the Weggl browser 3D-related programs, you can expect, clearly can run in the IE11, but the code if only the detection browser IE on strike and then very proud to pop up a hint "please switch to other browsers", ie is not very innocent ...

There is also a reason not only to detect browser is IE, that is, the browser itself there are differences, there are differences is normal, even in addition to IE Firefox,chrome,opera, Safari and the like, in the various web standards support and implementation is not exactly the same. That's why a style is debugged in Chrome, which is a bit awkward in ff. If it's the difference in JavaScript code, should we write a section of code that detects ff. Or one day found in opera a function out of the result is biased, that is to write a test of opera code, showing that this idea is problematic.

That's why modernizr.js have a reason to be useful. To ensure that the code is expected to work properly, we need to first detect whether the current browser supports this feature, if supported, okay, the code executes normally, and if not, execute another piece of code.

This article about jquery to remove the browser detection is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.