Skip to content

Instantly share code, notes, and snippets.

@carloscabo
Last active January 10, 2018 08:24
Show Gist options
  • Save carloscabo/1b92432965e141d03f27771b6212b98f to your computer and use it in GitHub Desktop.
Save carloscabo/1b92432965e141d03f27771b6212b98f to your computer and use it in GitHub Desktop.
Detects JS support and IE10/11 browser
/*
<html xml:lang="es" lang="es" class="not-ie no-js">
Replaces the `no-js` by `js` if browser has JS support and the `not-ie` by `ie` if we are in IE browser
Conditional comments are no longer supported in IE10 / 11 https://msdn.microsoft.com/en-us/library/hh801214(v=vs.85).aspx
Is recommended to be the FIRST js script app ;)
*/
(function(){
var
ua = window.navigator.userAgent;
document.documentElement.className = document.documentElement.className.replace('no-js', 'js');
if ( ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0 ) {
// Is IE 10 /11
document.documentElement.className = document.documentElement.className.replace('not-ie', 'ie');
}
})();
@carloscabo
Copy link
Author

Do not assign document.documentElement.className to a variable, seems that in some versions of IE does not work the .replace if it is not done over the document.documentElement.className property directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment