Skip to content

Instantly share code, notes, and snippets.

@oobleck
Last active June 11, 2024 09:46
Show Gist options
  • Select an option

  • Save oobleck/8428063 to your computer and use it in GitHub Desktop.

Select an option

Save oobleck/8428063 to your computer and use it in GitHub Desktop.
Modernizr tests for IE10 & IE11, since they removed conditional comments (and still haven't gotten browsers quite right)
// IE10
Modernizr.addTest('ie10', function() {
// http://stackoverflow.com/questions/9900311/how-do-i-target-only-internet-explorer-10-for-certain-situations-like-internet-e
'use strict';
var match = (/*@cc_on!@*/false && document.documentMode === 10);
return match;
});
// IE11
Modernizr.addTest('ie11', function() {
// https://en.wikipedia.org/wiki/Internet_Explorer_11
'use strict';
// var ua = navigator.userAgent;
// var match = /Trident.*rv[\s:]11\./i.test(ua);
// ('msTransform' in document.body.style)
var match = (!!document.documentMode &&
!document.all &&
(!!window.matchMedia || !!window.msMatchMedia) &&
!Modernizr.websqldatabase &&
!Modernizr.cssreflections);
return match;
});
@oobleck
Copy link
Copy Markdown
Author

oobleck commented Jan 14, 2014

These are not pretty, but they do work. Seems to also work (as in detects false) in the various document modes.

@petebarr
Copy link
Copy Markdown

Works for IE11 but not IE10 for me.

@SDShooter
Copy link
Copy Markdown

SDShooter commented Apr 14, 2017

The following addition to the IE11 check will prevent it from including Microsoft Edge browser.

return match && (window.navigator.userAgent.indexOf('Edge/') == -1)

It may be cleaner to check for features, but meanwhile, this works.

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