Detekcja przeglądarki / Chris Nott Drukuj
Ocena użytkowników: / 0
SłabyŚwietny 
Wpisany przez Jan Jackowicz-Korczyński   
czwartek, 19 listopada 2009 18:21

Umieszczony w <HEAD>:

 


001.// Browser Detect  v2.1.6
004.// code by Chris Nott (chris[at]dithered[dot]com)
005. 
006. 
007.function BrowserDetect() {
008.   var ua = navigator.userAgent.toLowerCase();
009. 
010.   // browser engine name
011.   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
012.   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
013. 
014.   // browser name
015.   this.isKonqueror   = (ua.indexOf('konqueror') != -1);
016.   this.isSafari      = (ua.indexOf('safari') != - 1);
017.   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
018.   this.isOpera       = (ua.indexOf('opera') != -1);
019.   this.isIcab        = (ua.indexOf('icab') != -1);
020.   this.isAol         = (ua.indexOf('aol') != -1);
021.   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
022.   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
023.   this.isFirebird    = (ua.indexOf('firebird/') != -1);
024.   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
025.    
026.   // spoofing and compatible browsers
027.   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
028.   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
029.    
030.   // rendering engine versions
031.   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
032.   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
033.   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
034.    
035.   // browser version
036.   this.versionMinor = parseFloat(navigator.appVersion);
037.    
038.   // correct version number
039.   if (this.isGecko && !this.isMozilla) {
040.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
041.   }
042.   else if (this.isMozilla) {
043.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
044.   }
045.   else if (this.isIE && this.versionMinor >= 4) {
046.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
047.   }
048.   else if (this.isKonqueror) {
049.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
050.   }
051.   else if (this.isSafari) {
052.      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
053.   }
054.   else if (this.isOmniweb) {
055.      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
056.   }
057.   else if (this.isOpera) {
058.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
059.   }
060.   else if (this.isIcab) {
061.      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
062.   }
063.    
064.   this.versionMajor = parseInt(this.versionMinor);
065.    
066.   // dom support
067.   this.isDOM1 = (document.getElementById);
068.   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
069.    
070.   // css compatibility mode
071.   this.mode = document.compatMode ? document.compatMode : 'BackCompat';
072. 
073.   // platform
074.   this.isWin    = (ua.indexOf('win') != -1);
075.   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
076.   this.isMac    = (ua.indexOf('mac') != -1);
077.   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
078.   this.isLinux  = (ua.indexOf('linux') != -1);
079.    
080.   // specific browser shortcuts
081.   this.isNS4x = (this.isNS && this.versionMajor == 4);
082.   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
083.   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
084.   this.isNS4up = (this.isNS && this.versionMinor >= 4);
085.   this.isNS6x = (this.isNS && this.versionMajor == 6);
086.   this.isNS6up = (this.isNS && this.versionMajor >= 6);
087.   this.isNS7x = (this.isNS && this.versionMajor == 7);
088.   this.isNS7up = (this.isNS && this.versionMajor >= 7);
089.    
090.   this.isIE4x = (this.isIE && this.versionMajor == 4);
091.   this.isIE4up = (this.isIE && this.versionMajor >= 4);
092.   this.isIE5x = (this.isIE && this.versionMajor == 5);
093.   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
094.   this.isIE5up = (this.isIE && this.versionMajor >= 5);
095.   this.isIE6x = (this.isIE && this.versionMajor == 6);
096.   this.isIE6up = (this.isIE && this.versionMajor >= 6);
097.    
098.   this.isIE4xMac = (this.isIE4x && this.isMac);
099.}
100. 
101.  
102. 
103. 
104.var browser = new BrowserDetect();

 


Ze strony:

http://morgenbladet.no/apps/pbcs.dll/forside

 

Zobacz podobne artykuły