Home > Web Front-end > JS Tutorial > Jquery determines the code of browsers such as IE6_jquery

Jquery determines the code of browsers such as IE6_jquery

WBOY
Release: 2016-05-16 18:08:28
Original
1105 people have browsed it
Jquery determines the code for IE6:
Copy code The code is as follows:

if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
//Code
}

jquery determines the browser method
jquery uses navigator.userAgent.indexOf to determine the browser type and does some processing. If you don’t want to use jquery, you can use it by slightly modifying the code
jquery Determine the source code of the browser (jquery1.31 as an example)
Js code:
Copy the code The code is as follows:

var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
jQuery.browser = {
version: (userAgent.match( /. ( ?:rv|it|ra|ie)[/: ]([d.] )/ ) || [0,'0'])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};

version---browser version
msie----ie browser (Microsoft Internet Explorer)
mozilla-Firefox browser
opera--opera browser
Js code:
var userAgent = navigator.userAgent.toLowerCase();
browser={
version: (userAgent.match( /. (?:rv|it|ra|ie)[/: ]([d.] )/ ) || [0,'0'])[1],
safari: / webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla : /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
}
The call is the same as jquery, just remove the $ symbol
Quote From: http://www.zdbase.com/content/detail.aspx?OID=F50C5170-4793-4C42-966C-823D48DA5879
Use Jquery to determine the type of browser, if only to determine the type of browser It is not recommended to use this method. It is only recommended if you have already used jquery, because there is no need to load such a large class library for such a small function.
It is recommended that friends who are learning jquery study it and understand the ideas.
Mainly used method: $.browser.['browser keyword']
The code is as follows:
Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template