Skip to content

Instantly share code, notes, and snippets.

@mneuhaus
Created December 9, 2014 09:58
Show Gist options
  • Save mneuhaus/5a43f8725d33401681b5 to your computer and use it in GitHub Desktop.
Save mneuhaus/5a43f8725d33401681b5 to your computer and use it in GitHub Desktop.
(function($) {
$(document).ready(function() {
window.onresize = function(){
var agent = navigator.userAgent;
var current_width = window.innerWidth;
var html = document.getElementsByTagName('html')[0];
if (agent.match(/Android.*Mobile|BlackBerry|iPhone|iPod|Opera Mini|IEMobile/i)) {
html.className = "mobile";
} else if (agent.match(/Android|iPad/i)) {
html.className = "tablet";
} else if (agent.match(/MSIE 8/i)){
html.className = "ie8";
} else if (agent.match(/MSIE 9/i)){
html.className = "ie9";
} else if (agent.match(/MSIE 10/i)){
html.className = "ie10";
} else if (agent.match(/MSIE 11/i)){
html.className = "ie11";
} else if (current_width < 481) {
html.className = "mobile";
} else if (current_width < 739) {
html.className = "tablet";
} else {
html.className = "desktop";
}
}();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment