问题
I have codes $.browser to detect the browser and upon the result some layout style is based. but now with ie 11, $.browser would give mozilla v.11. any suggestion to repair ?
回答1:
Try this:
var isIE11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
alert(isIE11);
EDIT:
Editted in a regex fix, taken from the comments. This fix works in the current version of IE11 as of 2/17/2014.
回答2:
That last one was correct.
Example:
To apply a body style for IE only for IE7 and above (including 10+11...)
Copy/Paste this code inside the <head></head>
tag:
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>//<![CDATA[
$(function(){
if(navigator.userAgent.match(/Trident\/7\./)) {
$('body').addClass('if-ie');
}
});//]]>
</script>
来源:https://stackoverflow.com/questions/20089145/how-to-detect-ie11-using-jquery