我想知道是否有可能显示警告或打开弹出窗口,这可能会将IE更新为最新版本或使用Firefox / Chrome / Safari,而浏览器是Internet Explorer IE8或更早版本…
<!--[if lt IE 9]> ...i should use code here... <![endif]-->
使用jQuery欺骗浏览器并加载jQuery lib是否明智?或者是否更好地使用常规JavaScript以避免旧版浏览器的其他问题?
解决方法
你有两个选择:
>解析User-Agent字符串
// Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). function getInternetExplorerVersion() { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); } } return rv; } function checkVersion() { var msg = "You're not using Internet Explorer."; var ver = getInternetExplorerVersion(); if ( ver > -1 ) { if ( ver >= 9.0 ) { msg = "You're using a recent copy of Internet Explorer." } else { msg = "You should upgrade your copy of Internet Explorer."; } } alert(msg); }
>使用条件评论:
<!--[if gte IE 9]> <p>You're using a recent version of Internet Explorer.</p> <![endif]--> <!--[if lt IE 8]> <p>Hm. You should upgrade your copy of Internet Explorer.</p> <![endif]--> <![if !IE]> <p>You're not using Internet Explorer.</p> <![endif]>