Created
May 9, 2013 13:16
-
-
Save chrisjhoughton/5547376 to your computer and use it in GitHub Desktop.
Show a message to people in IE8 or lower asking them to upgrade their browser. Depends on jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var BadBrowser = { | |
show: function() { | |
var _this = this; | |
if (_this.isIE8orLower()) { | |
_this.showMessage(); | |
} | |
}, | |
isIE8orLower: function() { | |
var version = this.getInternetExplorerVersion(); | |
if (version !== -1) { | |
return (version < 9); | |
} else { | |
return false; | |
} | |
}, | |
// Returns the version of Internet Explorer or a -1 | |
// (indicating the use of another browser). | |
getInternetExplorerVersion: function() { | |
var rv = -1; // Return value assumes failure. | |
if (navigator.appName == 'Microsoft Internet Explorer') { | |
var ua = navigator.userAgent; | |
var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})"); | |
if (re.exec(ua) !== null) rv = parseFloat(RegExp.$1); | |
} | |
return rv; | |
}, | |
showMessage: function() { | |
var html = $('<div/>', { | |
id: 'unsupported', | |
html: 'Your browser is unsupported on this site. Please <a style="text-decoration: underline" href="http://browsehappy.com/" target="_blank">upgrade</a> for the best experience.', | |
css: { | |
"z-index": "1001", | |
"border-bottom": "#d4c790 2px solid", | |
"position": "fixed", | |
"text-align": "center", | |
"line-height": "40px", | |
"background-color": "#faf4af", | |
"width": "100%", | |
"font-family": "sans-serif", | |
"height": "40px", | |
"font-size": "12px", | |
"top": "0px", | |
"left": "0px", | |
"color": "#333" | |
} | |
}); | |
console.log('showing'); | |
$('body').prepend(html); | |
$('#unsupported').show(); | |
} | |
}; | |
// Define as an AMD module for loaders such as RequireJS. | |
// If define doesn't exist, then just wait for document ready and show it. | |
if (typeof define === 'function' && define.amd) { | |
define('badbrowser', function() { | |
return BadBrowser; | |
}); | |
} else { | |
$(document).ready(function() { | |
BadBrowser.show(); | |
}); | |
} | |
}(window.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment