1/* 2 * Browser Detection 3 * © 2010 DevSlide Labs 4 * 5 * Visit us at: www.devslide.com/labs 6 */ 7var tridentVersion = navigator.userAgent; 8var agentValue = tridentVersion.match('Trident/([0-9]\.[0-9])'); 9if( agentValue === null || agentValue[1] < 6 ) { 10 11 12 var notSupportedBrowsers = [{'os': 'Any', 'browser': 'MSIE', 'version': 8}, {'os': 'Any', 'browser': 'MSIE', 'version': 7}, {'os': 'Any', 'browser': 'MSIE', 'version': 6}, {'os': 'Any', 'browser': 'MSIE', 'version': 5}]; 13 var displayPoweredBy = false; 14 var noticeLang = 'professional'; 15 var noticeLangCustom = null; 16 var supportedBrowsers = []; 17 18 var BrowserDetection = { 19 init: function(){ 20 if(notSupportedBrowsers == null || notSupportedBrowsers.length < 1){ 21 notSupportedBrowsers = this.defaultNotSupportedBrowsers; 22 } 23 24 this.detectBrowser(); 25 this.detectOS(); 26 27 if(this.browser == '' || this.browser == 'Unknown' || this.os == '' || 28 this.os == 'Unknown' || this.browserVersion == '' || this.browserVersion == 0) 29 { 30 return; 31 } 32 33 // Check if this is old browser 34 var oldBrowser = false; 35 for(var i = 0; i < notSupportedBrowsers.length; i++){ 36 if(notSupportedBrowsers[i].os == 'Any' || notSupportedBrowsers[i].os == this.os){ 37 if(notSupportedBrowsers[i].browser == 'Any' || notSupportedBrowsers[i].browser == this.browser){ 38 if(notSupportedBrowsers[i].version == "Any" || this.browserVersion <= parseFloat(notSupportedBrowsers[i].version)){ 39 oldBrowser = true; 40 break; 41 } 42 } 43 } 44 } 45 46 if(oldBrowser){ 47 this.displayNotice(); 48 } 49 }, 50 51 getEl: function(id){ return window.document.getElementById(id); }, 52 getElSize: function(id){ 53 var el = this.getEl(id); 54 if(el == null){ return null; } 55 return { 'width': parseInt(el.offsetWidth), 'height': parseInt(el.offsetHeight) }; 56 }, 57 getWindowSize: function(){ 58 if(typeof window.innerWidth != 'undefined'){ 59 return {'width': parseInt(window.innerWidth), 'height': parseInt(window.innerHeight)}; 60 } else { 61 if(window.document.documentElement.clientWidth != 0){ 62 return {'width': parseInt(window.document.documentElement.clientWidth), 'height': parseInt(window.document.documentElement.clientHeight)}; 63 } else { 64 return {'width': parseInt(window.document.body.clientWidth), 'height': parseInt(window.document.body.clientHeight)}; 65 } 66 } 67 }, 68 positionNotice: function(){ 69 var noticeSize = this.getElSize('browser-detection'); 70 var windowSize = this.getWindowSize(); 71 var noticeEl = this.getEl('browser-detection'); 72 73 if(noticeEl == null || noticeSize == null || windowSize == null || !windowSize.width || !windowSize.height){ return; } 74 noticeEl.style.left = (windowSize.width - noticeSize.width) / 2 + "px"; 75 76 var offset = (this.browser == "MSIE" && this.browserVersion < 7) ? (window.document.documentElement.scrollTop != 0 ? window.document.documentElement.scrollTop : window.document.body.scrollTop) : 0; 77 noticeEl.style.top = (windowSize.height - noticeSize.height - 20 + offset) + "px"; 78 this.noticeHeight = noticeSize.height; 79 }, 80 81 displayNotice: function(){ 82 if(this.readCookie('bdnotice') == 1){ 83 return; 84 } 85 86 this.writeNoticeCode(); 87 this.positionNotice(); 88 89 var el = this; 90 window.onresize = function(){ el.positionNotice(); }; 91 if(this.browser == "MSIE" && this.browserVersion < 7){ 92 window.onscroll = function(){ el.positionNotice(); }; 93 } 94 95 this.getEl('browser-detection-close').onclick = function(){ el.remindMe(false); }; 96 this.getEl('browser-detection-remind-later').onclick = function(){ el.remindMe(false); }; 97 this.getEl('browser-detection-never-remind').onclick = function(){ el.remindMe(true); }; 98 }, 99 100 remindMe: function(never){ 101 this.writeCookie('bdnotice', 1, never == true ? 365 : 7); 102 this.getEl('browser-detection').style.display = 'none'; 103 this.getEl('black_overlay').style.display = 'none'; 104 }, 105
106 writeCookie: function(name, value, days){ 107 var expiration = ""; 108 if(parseInt(days) > 0){ 109 var date = new Date(); 110 date.setTime(date.getTime() + parseInt(days) * 24 * 60 * 60 * 1000); 111 expiration = '; expires=' + date.toGMTString(); 112 } 113 114 document.cookie = name + '=' + value + expiration + '; path=/'; 115 }, 116 117 readCookie: function(name){ 118 if(!document.cookie){ return ''; } 119 120 var searchName = name + '='; 121 var data = document.cookie.split(';'); 122 123 for(var i = 0; i < data.length; i++){ 124 while(data[i].charAt(0) == ' '){ 125 data[i] = data[i].substring(1, data[i].length); 126 } 127 128 if(data[i].indexOf(searchName) == 0){ 129 return data[i].substring(searchName.length, data[i].length); 130 } 131 } 132 133 return ''; 134 }, 135 136 writeNoticeCode: function(){ 137 var title = ''; 138 var notice = ''; 139 var selectBrowser = ''; 140 var remindMeLater = ''; 141 var neverRemindAgain = ''; 142 143 var browsersList = null; 144 var code = '<div id="black_overlay"></div><div id="browser-detection"><a href="javascript:;" id="browser-detection-close">Close</a>'; 145 146 if(noticeLang == 'custom' && noticeLangCustom != null){ 147 title = noticeLangCustom.title; 148 notice = noticeLangCustom.notice; 149 selectBrowser = noticeLangCustom.selectBrowser; 150 remindMeLater = noticeLangCustom.remindMeLater; 151 neverRemindAgain = noticeLangCustom.neverRemindAgain; 152 } else { 153 var noticeTextObj = null; 154 eval('noticeTextObj = this.noticeText.' + noticeLang + ';'); 155 156 if(!noticeTextObj){ 157 noticeTextObj = this.noticeText.professional; 158 } 159 160 title = noticeTextObj.title; 161 notice = noticeTextObj.notice; 162 selectBrowser = noticeTextObj.selectBrowser; 163 remindMeLater = noticeTextObj.remindMeLater; 164 neverRemindAgain = noticeTextObj.neverRemindAgain; 165 } 166 167 notice = notice.replace("\n", '</p><p class="bd-notice">'); 168 notice = notice.replace("{browser_name}", (this.browser + " " + this.browserVersion)); 169 170 code += '<p class="bd-title">' + title + '</p><p class="bd-notice">' + notice + '</p><p class="bd-notice"><b>' + selectBrowser + '</b></p>'; 171 172 if(supportedBrowsers.length > 0){ 173 browsersList = supportedBrowsers; 174 } else { 175 browsersList = this.supportedBrowsers; 176 } 177 178 code += '<ul class="bd-browsers-list">'; 179 for(var i = 0; i < browsersList.length; i++){ 180 code += '<li class="' + browsersList[i].cssClass + '"><a href="' + browsersList[i].downloadUrl + '" target="_blank">' + browsersList[i].name + '</a></li>'; 181 } 182 code += '</ul>'; 183 184 if(displayPoweredBy){ 185 code += '<div class="bd-poweredby">Powered by <a href="http://www.devslide.com/labs/browser-detection" target="_blank">DevSlide Labs</a></div>'; 186 } 187 188 code += '<ul class="bd-skip-buttons">'; 189 code += '<li><button id="browser-detection-remind-later" type="button">' + remindMeLater + '</button></li>'; 190 code += '<li><button id="browser-detection-never-remind" type="button">' + neverRemindAgain + '</button></li>'; 191 code += '</ul>'; 192 code += '</div>'; 193 window.document.body.innerHTML += code; 194 }, 195 196 detectBrowser: function(){ 197 this.browser = ''; 198 this.browserVersion = 0; 199 200 if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 201 this.browser = 'Opera'; 202 } else if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 203 this.browser = 'MSIE'; 204 } else if(/Navigator[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 205 this.browser = 'Netscape'; 206 } else if(/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 207 this.browser = 'Chrome'; 208 } else if(/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
209 this.browser = 'Safari'; 210 /Version[\/\s](\d+\.\d+)/.test(navigator.userAgent); 211 this.browserVersion = new Number(RegExp.$1); 212 } else if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 213 this.browser = 'Firefox'; 214 } 215 216 if(this.browser == ''){ 217 this.browser = 'Unknown'; 218 } else if(this.browserVersion == 0) { 219 this.browserVersion = parseFloat(new Number(RegExp.$1)); 220 } 221 }, 222 223 // Detect operation system 224 detectOS: function(){ 225 for(var i = 0; i < this.operatingSystems.length; i++){ 226 if(this.operatingSystems[i].searchString.indexOf(this.operatingSystems[i].subStr) != -1){ 227 this.os = this.operatingSystems[i].name; 228 return; 229 } 230 } 231 232 this.os = "Unknown"; 233 }, 234 235 // Variables 236 noticeHeight: 0, 237 browser: '', 238 os: '', 239 browserVersion: '', 240 supportedBrowsers: [ 241 { 'cssClass': 'firefox', 'name': 'Mozilla Firefox', 'downloadUrl': 'http://www.getfirefox.com/' }, 242 { 'cssClass': 'chrome', 'name': 'Google Chrome', 'downloadUrl': 'http://www.google.com/chrome/' }, 243 { 'cssClass': 'msie', 'name': 'Internet Explorer', 'downloadUrl': 'http://www.getie.com/' }, 244 { 'cssClass': 'opera', 'name': 'Opera', 'downloadUrl': 'http://www.opera.com/' }, 245 { 'cssClass': 'safari', 'name': 'Apple Safari', 'downloadUrl': 'http://www.apple.com/safari/' } 246 ], 247 operatingSystems: [ 248 { 'searchString': navigator.platform, 'name': 'Windows', 'subStr': 'Win' }, 249 { 'searchString': navigator.platform, 'name': 'Mac', 'subStr': 'Mac' }, 250 { 'searchString': navigator.platform, 'name': 'Linux', 'subStr': 'Linux' }, 251 { 'searchString': navigator.userAgent, 'name': 'iPhone', 'subStr': 'iPhone/iPod' } 252 ], 253 defaultNotSupportedBrowsers: [{'os': 'Any', 'browser': 'MSIE', 'version': 6}], 254 noticeText: { 255 'professional': { "title": "Outdated Browser Detected", "notice": "Our website has detected that you are using an outdated browser. Using your current browser will prevent you from accessing features on our website. An upgrade is not required, but is strongly recommend to improve your browsing experience on our website.", "selectBrowser": "Use the links below to download a new browser or upgrade your existing browser.", "remindMeLater": "Remind me later", "neverRemindAgain": "No, don't remind me again" }, 256 'informal': { "title": "Whoaaa!", "notice": "It appears you're using an outdated browser which prevents access to some of the features on our website. While it's not required, you really should <b>upgrade or install a new browser</b>!", "selectBrowser": "Visit the official sites for popular browsers below:", "remindMeLater": "Not now, but maybe later", "neverRemindAgain": "No, don't remind me again" }, 257 'technical': { "title": "Old Browser Alert! <span class='bd-highlight'>DEFCON 5</span>", "notice": "Come on! If you are hitting our site, then you must at least be partially tech savvy. So, why the older browser? We're not asking you to brush off your old Fibonacci Heap and share it with the class. Just upgrade!\nI know, I know. You don't like to be told what to do. But, we're only asking you to upgrade so you can access all the latest, greatest features on our site. It's quick and easy. But, if you still want to skip it, that's cool. We will still welcome you — and your creepy old browser. :P", "selectBrowser": "Visit the official sites for popular browsers below:", "remindMeLater": "Remind me later", "neverRemindAgain": "No, don't remind me. I like my Commodore 64!" }, 258 'goofy': { "title": "Are You Serious?", "notice": "Are you really using <b>{browser_name}</b> as your browser?\nYou're surfing the web on a dinosaur (a dangerous one too — like a Tyrannosaurus or Pterodactyl or something scary like that). <b>Get with it and upgrade now!</b> If you do, we promise you will enjoy our site a whole lot more. :)", "selectBrowser": "Visit the official sites for popular browsers below:", "remindMeLater": "Maybe Later", "neverRemindAgain": "No, don't remind me again" }, 259 'mean': { "title": "Umm, Your Browser Sucks!", "notice": "Get a new one here.", "selectBrowser": "Official sites for popular browsers:", "remindMeLater": "Remind me later, a'hole", "neverRemindAgain": "F' off! My browser rocks!" } 260 } 261 }; 262 263 264 window.onload = function(){ 265 BrowserDetection.init(); 266 }; 267 268}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.