Why does jQuery remove browser detection?

Source: Internet
Author: User

Many cutting-edge frontend technologies need to consider whether IE supports HTML5-related projects. Previously, jQuery. browser can be easily called for implementation.

If(jQuery.browser.msie) alert(“DIE IE!”)

But this convenience no longer exists after jQuery 1.9. Suddenly I felt like I lost my closest comrade-in-arms, a good friend that I could not do without when I was engaged in development, and a good tool that I could not write cross-browser front-end code when I left. I don't know how to do it.

Every time I need to consider IE, I will go to google to check how to use jQuery of version 1.9 to detect IE. However, most of the answers on StackOverFlow tell me that jQuery1.9 is useless. browser. jQuery is recommended. support, but no one told me why.

I don't know if my mind was stuck in the door for a long time, but why did I get rid of it? My goal is to check whether the current user is using IE. If not, then I need to pop up the relevant prompt to tell the user that you are using IE, some features may not be supported by cloud...

Helpless, so that my code returned to the stone age without jQuery, and I used the most primitive and plain JavaScript code to detect IE, since countless predecessors have accumulated a lot of experience in the game with IE, and there have been more than N existing methods, I can choose one. In addition, each time it is used, it is still different. The next time I try to detect IE, I will go to Google again to get another piece of code to achieve the same effect.

However, the question is awkward. In order to detect an Internet Explorer, you need to add a large piece of code that is ugly and irrelevant to the page function logic. This is like installing a cracking software and being bundled with a large number of AD plug-ins.

Recently, with the release of windows, I casually followed IE11. The official team said this product will support WegGL technology! IE11 will support this technology that Microsoft has been abandoning. This is not surprising. The reason is that Internet Explorer has been regarded by frontend staff as a wonderful start as early as Internet Explorer 6. After so many years, developers have not been able to coexist with Internet Explorer.

But does IE11 support the relationship between WebGL and wool in this article? It doesn't matter much, But I suddenly realized that Three. js in the HTML5 project can run on IE, at least on IE11! Therefore, the earlier IE detection seems very logical. I seem to see a piece of gold coming out of my previous misunderstanding: I really don't need to check whether the Internet browser is used by users. Our goal is to make the code run normally. If the current browser supports the features in our code, it will run normally. If not, the strike will prompt you.

So I seem to understand why jQuery does not support jQuery in 1.9. browser, and then gave the support API. When I searched again for problems related to IE, we also suggested using Modernizr. js (a JavaScript library that checks the browser's support for HTML5 and CSS3 ).

Because IE detection is unscientific. Although some HTML5 features are not supported by IE, they are constantly updated, so it does not mean they are not supported by later versions. Therefore, it would be rather unscientific if the Code contains very straightforward Code specifically for IE. As mentioned above, the 3D-related program in WegGL browser can be expected to run in IE11, however, if the Code only detects Browser IE, it will strike and then proudly bring up a prompt "Please use another browser". Is IE innocent...

There is also another reason not only to check whether the browser is IE, that is, there is a difference between the browsers themselves, the difference is normal, even in addition to IE FireFox, Chrome, Opera, safari and others are not completely consistent in the support and implementation of various Web standards. That's why debugging a style in Chrome is normal, and it seems awkward in FF. If it is a difference in JavaScript code, should we write another code to detect FF. Or if the result of a function in Opera is biased one day, you have to write a code to detect the Opera. This idea is wrong.

That's why Modernizr. js is useful. To ensure the normal implementation of the code, we need to first check whether the current browser supports this function. If yes, the code can be normally executed. If not, execute another piece of code.

 

 

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.