What\'s the least error-prone way to target just IE11 with JavaScript?
Note: This should really only be done for analytics or informing the user what browser they\'r
This will set ie
to the version of IE, or 0 if none. It'll work for 1 through 11, but may not detect future versions if Microsoft drops the Trident engine.
var ie = 0;
try { ie = navigator.userAgent.match( /(MSIE |Trident.*rv[ :])([0-9]+)/ )[ 2 ]; }
catch(e){}
You may also be interested in my related, more detailed answer here.