如何向IE6 / IE7瀏覽器顯示消息以升級到IE8並讓IE8不顯示IE7警告?

[英]How can I show a message to IE6/IE7 browsers to upgrade to IE8 and have IE8 not show the IE7 warning?

I want to only allow users with IE8 (not IE6, IE7) or another browser to access my site when logged in.


I followed: http://code.google.com/p/ie6-upgrade-warning/ But I also wanted it to not allow IE7 users to use the main site when logged in (they can view public pages.) The reason is that the main web application has a lot of JavaScript effects that will only work 100% in IE8 rendering mode (or any other browser aside from IE.)


The problem with modifying the ie6 upgrade warning to be ie7 is that it looked like IE8 displayed my webpage in an IE7 rendering mode and "lies" about being ie7 and triggers the IE7 stylesheet code.


So how can I force IE8 to always render my page in IE8 mode?


13 个解决方案


Use this tag:


<meta http-equiv="X-UA-Compatible" content="IE=8" />


Correction to AdamSane's example:


<!--[if lt IE 8]> Special instructions for IE 7 or less here <![endif]-->

IE 7或更少的特殊說明


here is a good link that suggest some solution



personally i like fourth solution(http://www.browser-update.org/)


just a piece of cake



Personally I would recommend users to upgrade IE for security reasons. I would use a conditional comment to target browsers below IE8.


      <!--[if lt IE 8]>You are using an outdated version of Internet Explorer.  For security reasons you should upgrade your browser. Please go to Windows Updates and install the latest version.<![endif]-->

This message should be unobtrusive but graceful. You should also make the website usable for those that cannot upgrade their browsers.



Rather than try to force IE 8+ mode, I use a combination of conditional comments and a simple javascript check. The document.documentMode property was added to IE in version 8, so if it exists at all (regardless of value, though it HAS to be 7 with this code) it means we're in compatibility mode and should not show the warning:

我沒有嘗試強制使用IE 8+模式,而是使用條件注釋和簡單的javascript檢查相結合。 document.documentMode屬性在版本8中被添加到IE中,所以如果它存在(無論值是多少,盡管它與此代碼一樣是7),這意味着我們處於兼容模式並且不應該顯示警告:

<!--[if lte IE 7]>
        if (!document.documentMode) { //if documentMode exists, this is a later IE in compatibility mode


Here is this cool script that works for all old browsers:


<script type="text/javascript"> 
    var $buoop = {vs:{i:7,f:5,o:12,s:5,n:9}}; 
    $buoop.ol = window.onload; 
     try {if ($buoop.ol) $buoop.ol();}catch (e) {} 
     var e = document.createElement("script"); 
     e.setAttribute("type", "text/javascript"); 
     e.setAttribute("src", "//browser-update.org/update.js"); 

Note: If the visitor ignores the advice, it won't appear again for some time.


More can be found: here



Depends on how you've coded your (X)HTML, but IE8 should use standards mode (not IE7 mode) if you have a strict doctype like:


<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

at the top of your HTML files.


XHTML 1.0 Specs - Strictly Conforming Documents

XHTML 1.0規范 - 嚴格符合文檔

Here's a good post about how different doctypes/etc affect IE8's rendering mode: Understanding Compatibility Modes in Internet Explorer 8

這是一篇關於不同doctypes / etc如何影響IE8渲染模式的好文章:了解Internet Explorer 8中的兼容模式


Probably the best way would be to detect the user's browser User-Agent string and redirect them to a page asking them to upgrade (or download a different browser such as firefox or chrome) if they are using an old version of IE. You can see examples of the user agents of IE 7 and 8 on this IE developer blog entry. Older versions of IE follow a similar pattern.

可能最好的方法是檢測用戶的瀏覽器用戶代理字符串並將其重定向到要求他們升級(或下載其他瀏覽器,如firefox或chrome)的頁面(如果他們使用舊版本的IE)。您可以在此IE開發人員博客條目中查看IE 7和8的用戶代理示例。較早版本的IE遵循類似的模式。

One thing you should not do, however, is assume that any user agent string not following a certain pattern is invalid. Just check for MSIE ([0-9]) and see if it's in range; if it's missing entirely, assume the browser is supported. If it's MSIE 7, then further check for the Trident marker indicating compatiblity mode (and, I suppose, ask the user to turn it off). This will allow for other, future upstart browsers to have a fighting chance at rendering your page without turning them away at the door :)

但是,您不應該做的一件事是假設任何不遵循某種模式的用戶代理字符串都是無效的。只需檢查MSIE([0-9])並查看它是否在范圍內;如果它完全丟失,則假設支持瀏覽器。如果它是MSIE 7,那么進一步檢查三叉戟標記指示兼容模式(並且,我想,要求用戶將其關閉)。這將允許其他未來的新興瀏覽器在渲染您的頁面時有機會而不會將它們轉移到門外:)


As has been mentioned I'd suggest the best way to achieve this is to use conditional comments to include a stylesheet specific to all versions of IE earlier than 8:


<!--[if lt IE 8]> Include CSS here <![endif]-->

The included CSS could set a warning to be visible or perhaps enable an overlay on the page which 'locks' users out. It might be a good idea to include some rules which hide important elements on the page which could otherwise confuse the user if they do not work as intended.


Your other option is to redirect the user to another page - I'm not a huge fan of redirects but if used with care they can be a suitable solution.

您的另一個選擇是將用戶重定向到另一個頁面 - 我不是重定向的忠實粉絲,但如果小心使用它們可能是一個合適的解決方案。

Have you considered why you're locking a large amount of users out of your site? Maybe you should take the time to work out how to either gracefully degrade your JavaScript, or the other way around; 'progressively enhance' with JavaScript.


On the other hand, you might have control over the systems used by the organisation using your site in which case you're probably OK locking people out for using non-standard systems.



You can use CSS Conditional Comments


<!--[if IE 8]>
Special instructions for IE 6 here


Using javascript you can ask which browser have sent the request>


<script type="text/javascript">
function detectBrowser()
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if (browser=="Microsoft Internet Explorer")
  && (version>=8))
  alert("Your browser is good enough!");
  alert("It's time to upgrade your browser!");


Is this party over? ><

這個派對結束了嗎? > <

It is, but I think the information here can be updated a bit.


By today's standards, "today" being October 29 of 2013, you can use this meta tag to trigger the latest IE Browser and Document modes and trigger the installation of Google's Chrome Frame in older IEs:

根據今天的標准,“今天”是2013年10月29日,您可以使用此元標記觸發最新的IE瀏覽器和文檔模式,並觸發在舊版IE中安裝Google Chrome框架:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

This allows you to server specific IE6/7 styles. Keep in mind that I'm saying 'styles' not 'style sheets', meaning: You'd only use a single CSS file and in it are all your IE6 and IE7 styles. This is to minimize HTTP requests... but that's a totally different conversation.

這允許您服務器特定的IE6 / 7樣式。請記住,我說'樣式'不是'樣式表',這意味着:你只使用一個CSS文件,其中包括你的IE6和IE7樣式。這是為了最小化HTTP請求......但這是一個完全不同的對話。

Anyway, with the above snippet there's no need for scripts or Conditional Comments.


Note: Google Chrome Frame will be retired in January 2014 - more info here.

注意:Google Chrome Frame將於2014年1月停用 - 此處提供更多信息。


The very idea that you're "banning" IE 6 and 7 users from your website is ridiculous. A lot of people can't upgrade their browser or install another one because of work restrictions or because they don't know how. Barring these people from using your site will just cost you users in the long run.

您從網站“禁止”IE 6和7用戶的想法是荒謬的。由於工作限制或者他們不知道如何,許多人無法升級他們的瀏覽器或安裝另一個瀏覽器。禁止這些人使用您的網站從長遠來看只會讓您的用戶付出代價。

Either fix your JavaScript, work around the problems or gracefully degrade so that the site will work well even if it's turned off.


EDIT: I posted some more information in a comment below which should really be in this post:


It's often possible to detect IE and work around it. Hell, you can even use conditional comments to load a different version of the JavaScript. Using a JS framework will abstract away the differences between browsers to a level you don't need to worry about. Or just grab IE7.js and stick that on the site - I hear it gets things working like you wouldn't believe.

通常可以檢測IE並解決它。天哪,你甚至可以使用條件注釋來加載不同版本的JavaScript。使用JS框架將瀏覽器之間的差異抽象到您不必擔心的級別。或者只是抓住IE7.js並將其粘貼在網站上 - 我聽說它讓你的工作變得像你不相信的那樣。



粤ICP备14056181号  © 2014-2021 ITdaan.com