提问人:DanielAttard 提问时间:1/26/2012 最后编辑:rodrigoapDanielAttard 更新时间:9/13/2020 访问量:8156
阻止使用 Internet Explorer 查看页面
Prevent viewing page using Internet Explorer
问:
我开发了一个在 Chrome、Safari、Firefox 和 Opera 等现代浏览器中看起来很棒的网站,但是,它在旧版本的 Internet Explorer 中看起来很糟糕。
我是否可以使用一些代码来阻止页面在检测到旧版本的 IE 时加载?
也许代码可以加载不同的页面?
关于如何最好地实现这一目标的任何想法?谢谢。
答:
在 HTML 中使用 Internet Explorer 条件注释
<!--[if lt IE 9]>
Insert your IE code, like possible redirection or alteration of your page
<![endif]-->
评论
您可能需要考虑将 Chrome 框架添加到您的网页中。http://code.google.com/chrome/chromeframe/
评论
可以使用字符串 in 查找包含 Internet Explorer 特有字符串的用户代理。然后,您可以发出或重定向到另一个页面,该页面警告IE的危险。USER_AGENT
$_SERVER
header("Location: google.com")
评论
看看这个:
是的,当然,您可以使用客户端重定向或服务器端重定向。 或 您可以根据浏览器显示不同的内容。
Javascript/jQuery:
if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
// Do IE specific Tasks
// window.location = "http://somewhat.com"
}else{
//Do other tasks
}
PHP的:
<?php
$browser = get_browser(null, true);
print_r($browser);
?>
评论
您是否在网站中使用jQuery?
如果是这样,您可以利用 browser-validator-js (https://github.com/bml3i/browser-validator-js) 向用户显示友好的消息,如果他们使用任何版本的 IE。只需将 browser-validator-js 和 jQuery 包含在 HTML HEAD 中,并将以下代码添加到 HTML BODY 中即可。
<script type="text/javascript">
$(document).ready(function () {
BrowserValidator.validateBrowser();
});
</script>
这是一个示例:http://blog.bigcay.com/demo/browser_validator_demo.html
对我来说,它适用于
<script>
if (window.navigator.userAgent.indexOf("Trident/") > 0) {
alert("Internet Explorer is not supported.")
window.location.replace("https://example.com/ie")
}
</script>
评论