【发布时间】:2012-02-19 03:18:53
【问题描述】:
我开发的网站在 Chrome、Safari、Firefox 和 Opera 等现代浏览器中看起来很棒,但在旧版本的 Internet Explorer 中看起来很糟糕。
如果检测到旧版本的 IE,我是否可以使用一些代码来阻止页面加载?
也许代码可以加载不同的页面?
关于如何最好地实现这一点的任何想法?谢谢。
【问题讨论】:
标签: internet-explorer browser cross-browser
我开发的网站在 Chrome、Safari、Firefox 和 Opera 等现代浏览器中看起来很棒,但在旧版本的 Internet Explorer 中看起来很糟糕。
如果检测到旧版本的 IE,我是否可以使用一些代码来阻止页面加载?
也许代码可以加载不同的页面?
关于如何最好地实现这一点的任何想法?谢谢。
【问题讨论】:
标签: internet-explorer browser cross-browser
是的,您可以使用客户端重定向或服务器端重定向。 要么 您可以根据浏览器显示不同的内容。
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);
?>
【讨论】:
在您的 HTML 中使用 Internet Explorer 条件 cmets
<!--[if lt IE 9]>
Insert your IE code, like possible redirection or alteration of your page
<![endif]-->
【讨论】:
您可以使用$_SERVER 中的USER_AGENT 字符串来查找包含Internet Explorer 独有字符串的用户代理。然后,您可以发出header("Location: google.com") 或重定向到警告IE 危险的不同页面。
【讨论】:
您可能需要考虑将 Chrome Frame 添加到您的网页。 http://code.google.com/chrome/chromeframe/
【讨论】:
【讨论】:
您在您的网站中使用 jQuery 吗?
如果是这样,您可以利用 browser-validator-js (https://github.com/bml3i/browser-validator-js) 向使用任何版本 IE 的用户显示友好消息。只需在 HTML HEAD 中包含 browser-validator-js 和 jQuery,并将以下代码添加到 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>
【讨论】: