【发布时间】:2016-03-12 17:09:22
【问题描述】:
对于使用 IE 7 或更低版本访问网站的所有用户,我希望显示一条消息并且仅此消息,而不显示 body 或网站的任何其他部分。
在head中有此代码
<head>
<!-- Target IE 7 EQUAL and LOWER (7, 6, 5, ..) -->
<!--[if lte IE 7]>
<div id="ie7lower">
<a href="http://browsehappy.com/">
<p>Click here to update your browser..</p>
</a>
</div>
<style type="text/css">body {display:none;}</style>
<![endif]-->
</head>
<body>
...
我假设应该显示 div id ie7lower,因为它仍然在 head 中,并且使用内联样式我告诉 body 不要显示。
但是,一旦我使用内联样式,div id ie7lower 也会被隐藏。
可能是 IE 7 及更低版本将head 放在body 内,或者假设head 是body 的一部分,因此div id ie7lower 也不再显示?
基本上,我想为使用 IE 7 及更低版本的用户隐藏甚至不加载整个网站,并简单地向他们显示更新浏览器的消息。如果不用 JavaScript 也能做到这一点,那就太好了。
编辑
在隐藏不显示包装器的页面内容时,这是我想要做的解决方案,这也确实在条件 cmets 中加载了所有其他脚本和 CSS。
尝试尽可能减少 HTTP 请求并快速将 IE 7 和更低版本的用户引导至“更新您的浏览器”消息/页面,我使用 Redirect to another page without loading current page in jquery 将他们重定向到同一域上的最小页面,同时不加载我为 IE 8 和 IE 9 准备的所有额外脚本和 CSS。
<!-- https://stackoverflow.com/questions/33252945/redirect-to-another-page-without-loading-current-page-in-jquery -->
<!--[if lte IE 8]>
<script type="text/javascript">
location.replace('ie/outdated.html');
</script>
<![endif]-->
如果您的outdated.html 在同一个域中,请注意不要在ie/outdated.html 前面加上/!
如果有人感兴趣,这是“过时 IE”消息/页面的起点。
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Company Name | maximum 64 characters long title</title>
<meta name="description" content="Site description | maximum 130 chars long description for search engine snippet">
<!-- http://blog.powermapper.com/blog/post/Page-Title-Length-for-Search-Engines.aspx -->
</head>
<body>
<div id="outdated_container" style="text-align: center; margin: 0 auto;">
<h1>You are using an <strong>outdated</strong> browser that does not support this website's features.</h1>
<h1><a href="http://browsehappy.com/">Please upgrade your browser</a> to improve your web experience.</h1>
</div>
</body>
</html>
使用这种方法我只是得到
"GET /Domain/ HTTP/1.1" 200 7866
"GET /Domain/ie/outdated.html HTTP/1.1" 200 1017
而不是普通网站对所有浏览器以及 IE 8 和 IE 9 的所有其他 HTTP 请求。
这意味着 JS 必须在 IE 7 及更低版本中默认启用。鉴于现在这很可能是一小部分用户(在禁用 IE 7 和 JS 的情况下上网),我可以接受这种方法。
【问题讨论】:
-
你真的还有足够的 IE6 / IE7 用户来证明甚至费心告诉他们升级吗?
标签: html css internet-explorer