Home >Web Front-end >JS Tutorial >How does jquery determine whether it is an IE browser?
Jquery method to determine whether it is an IE browser: You can use the jquery browser method to determine, such as [$.browser.msie]. If we still need to distinguish the version, we need to use [jQuery.browser.version 】method.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version. This method is suitable for all brands of computers.
(Learning video sharing: javascript video tutorial)
Jquery method to determine whether it is an IE browser:
JQuery You can use the jQuery.browser method to determine the browser type. The return value can be: safari, opera, msie, mozilla. If the return value is msie, it means the browser is ie.
Of course sometimes we also need to distinguish versions, which requires the use of jQuery.browser.version.
Example:
function JudgeBroswer() { if($.browser.msie) { alert("this is msie!"); //IE } else if($.browser.safari) { alert("this is safari!"); //Safari } else if($.browser.mozilla) { alert("this is mozilla!"); //Firefox } else if($.browser.opera) { alert("this is opera"); //Opera } }
jquery source code:
var userAgent = navigator.userAgent.toLowerCase(); // Figure out what browser is being used jQuery.browser = { version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1], safari: /webkit/.test(userAgent), opera: /opera/.test(userAgent), msie: /msie/.test(userAgent) && !/opera/.test(userAgent), mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent) };
Related recommendations: js tutorial
The above is the detailed content of How does jquery determine whether it is an IE browser?. For more information, please follow other related articles on the PHP Chinese website!