Pro*_*raz 6 javascript jquery internet-explorer internet-explorer-8
我想知道是否有可能显示警告或打开弹出窗口,这可能会将IE更新为最新版本或使用Firefox/Chrome/Safari,而浏览器是Internet Explorer IE8或更早版本...
我想我应该在标签内使用下面的代码......
<!--[if lt IE 9]>
...i should use code here...
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
使用jQuery欺骗浏览器并加载jQuery lib是否明智?或者是否更好地使用常规JavaScript以避免旧版浏览器的其他问题?
您有两种选择:
解析了 User-Agent String
// 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);
}
Run Code Online (Sandbox Code Playgroud)使用条件评论:
<!--[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]>
Run Code Online (Sandbox Code Playgroud)参考:更有效地检测Windows Internet Explorer
<script> var ISOLDIE = false; </script>
<!--[if lt IE 9]>
<script> var ISOLDIE = true; </script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
然后,您想要在代码中绘制支持旧版IE的行:
<script>
if(ISOLDIE) {
alert("Your browser currently does not support this feature. Please upgrade.");
window.location = 'http://google.com/chrome';
}
</script>
Run Code Online (Sandbox Code Playgroud)
完全删除IE8支持通常不是一个好主意,这就是为什么我认为上面的解决方案是一个很好的折衷,因为你可以将它添加到你的网站/网络应用程序的组件,这些组件根本无法支持IE8,但是你可能(可能)仍然支持IE8在您网站的其他区域.
归档时间: |
|
查看次数: |
17813 次 |
最近记录: |