Js determines the browser type

Source: Internet
Author: User

Today, there is another hard-hit issue: how to determine the browser version through js. When I was a beginner, I tried to determine my own writing method. Later, I used a lot of jquery libraries and so on. I forgot about this. I remember when I read ibw code, I found a piece of related code, however, it has been in the draft box and has not been published. Show, show, and try again next time:


[Javascript]
_ T. Browser = function (sUA) {// IBW. Tool. Browser
Var win = window,
C = function (r ){
Return r. test (sUA );
},
IsIE =! + '\ V1 ',
IsTrident = isIE | !! Win. XDomainRequest,
IsWebkit =! IsTrident &&! Navigator. taintEnabled;
Return {
// Browser sniffing
IsIE: isIE,
IsIE6: isIE &&(! Win. XMLHttpRequest | !! Win. XMLHttpRequest. constructor ),
IsIE7: isIE &&!! Win. XMLHttpRequest &&! Win. XMLHttpRequest. constructor &&! Win. XDomainRequest,
IsIE8: isIE &&!! Win. XDomainRequest,
IsIE9 :! IsIE &&!! Win. XDomainRequest,
IsMaxthon :! Win. opera &&!! Win. external & typeof external. max_version! = 'Undefined', // an exception is thrown when opera reads external. external is null.
IsTT: c (/; TencentTraveler /),
Is360: c (/; 360 /),
IsSogou: c (/; SE \ d \./),
// Rendering engine sniffing.
IsWebkit: isWebkit, // safari chrome KHTML rendering engine .!! + '\ V1' prevents ie 6 from reporting errors
IsGecko :!! Document. getBoxObjectFor | win. policinnerscreenx! = Null, // firefox Rendering Engine
IsTrident: isTrident, // ie Rendering Engine
IsPresto :!! Win. opera, // opera Rendering Engine
 
// Extended sniffing
 
// Determine whether it is a high-speed sougou Browser
IsFastModeSogou: isWebkit &&!! Win. external & win. external. propertyIsEnumerable ('startpagecall '),
 
// Determine whether it is a high-speed sougou browser and need to trigger reflow (sougou2.0 fastMode) in flash mode)
IsFastModeSogouNeedReflow: isWebkit &&!! Win. external & win. external. propertyIsEnumerable ('startpagecall ')&&! ('Localdb' in external ),
 
// Determine whether it is a high-speed QQ5 Browser
IsFastModeQQ: isWebkit & win. external & 'webcorver 'in external,
 
// Determine whether iframe is supported to fix the flash div bug
IsIframeOnFlash: isTrident | function () {for (var o in {,}) return o = '0'; return '_'} () | (win. export innerscreenx = null &&!! Document. getBoxObjectFor)
};
} (Win. navigator. userAgent );

_ T. Browser = function (sUA) {// IBW. Tool. Browser
Var win = window,
C = function (r ){
Return r. test (sUA );
},
IsIE =! + '\ V1 ',
IsTrident = isIE | !! Win. XDomainRequest,
IsWebkit =! IsTrident &&! Navigator. taintEnabled;
Return {
// Browser sniffing
IsIE: isIE,
IsIE6: isIE &&(! Win. XMLHttpRequest | !! Win. XMLHttpRequest. constructor ),
IsIE7: isIE &&!! Win. XMLHttpRequest &&! Win. XMLHttpRequest. constructor &&! Win. XDomainRequest,
IsIE8: isIE &&!! Win. XDomainRequest,
IsIE9 :! IsIE &&!! Win. XDomainRequest,
IsMaxthon :! Win. opera &&!! Win. external & typeof external. max_version! = 'Undefined', // an exception is thrown when opera reads external. external is null.
IsTT: c (/; TencentTraveler /),
Is360: c (/; 360 /),
IsSogou: c (/; SE \ d \./),
// Rendering engine sniffing.
IsWebkit: isWebkit, // safari chrome KHTML rendering engine .!! + '\ V1' prevents ie 6 from reporting errors
IsGecko :!! Document. getBoxObjectFor | win. policinnerscreenx! = Null, // firefox Rendering Engine
IsTrident: isTrident, // ie Rendering Engine
IsPresto :!! Win. opera, // opera Rendering Engine

// Extended sniffing

// Determine whether it is a high-speed sougou Browser
IsFastModeSogou: isWebkit &&!! Win. external & win. external. propertyIsEnumerable ('startpagecall '),

// Determine whether it is a high-speed sougou browser and need to trigger reflow (sougou2.0 fastMode) in flash mode)
IsFastModeSogouNeedReflow: isWebkit &&!! Win. external & win. external. propertyIsEnumerable ('startpagecall ')&&! ('Localdb' in external ),

// Determine whether it is a high-speed QQ5 Browser
IsFastModeQQ: isWebkit & win. external & 'webcorver 'in external,

// Determine whether iframe is supported to fix the flash div bug
IsIframeOnFlash: isTrident | function () {for (var o in {,}) return o = '0'; return '_'} () | (win. export innerscreenx = null &&!! Document. getBoxObjectFor)
};
} (Win. navigator. userAgent );

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.