如何向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.

我想只允許用戶使用IE8(不是IE6,IE7)或其他瀏覽器登錄時訪問我的網站。

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.)

我跟着:http://code.google.com/p/ie6-upgrade-warning/但我也希望它不允許IE7用戶在登錄時使用主站點(他們可以查看公共頁面。)原因是主Web應用程序有很多JavaScript效果,只能在IE8渲染模式(或IE以外的任何其他瀏覽器)中100%工作。

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.

將ie6升級警告修改為ie7的問題在於它看起來像IE8以IE7呈現模式顯示我的網頁並且“謊言”是關於ie7並觸發IE7樣式表代碼。

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

那么如何強制IE8始終以IE8模式呈現我的頁面?

13 个解决方案

#1


Use this tag:

使用此標記:

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

#2


Correction to AdamSane's example:

更正AdamSane的例子:

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

IE 7或更少的特殊說明

#3


here is a good link that suggest some solution

這是一個很好的鏈接,提出了一些解決方案

http://garmahis.com/tools/ie6-update-warning/

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

我個人喜歡第四種解決方案(http://www.browser-update.org/)

just a piece of cake

只是一塊蛋糕

#4


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

我個人建議用戶出於安全原因升級IE。我會使用條件注釋來定位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.

這條消息應該不引人注目但優雅。您還應該使網站可用於那些無法升級其瀏覽器的網站。

#5


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]>
    <script>
        if (!document.documentMode) { //if documentMode exists, this is a later IE in compatibility mode
            showBadBrowserMessage();
        }
    </script>
<![endif]-->

#6


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; 
    window.onload=function(){ 
     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"); 
     document.body.appendChild(e); 
    } 
</script> 

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

注意:如果訪問者忽略了建議,它將不會再出現一段時間。

More can be found: here

可以找到更多:這里

#7


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:

取決於你如何編碼你的(X)HTML,但如果你有一個嚴格的doctype,IE8應該使用標准模式(不是IE7模式):

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

at the top of your HTML files.

在HTML文件的頂部。

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中的兼容模式

#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,那么進一步檢查三叉戟標記指示兼容模式(並且,我想,要求用戶將其關閉)。這將允許其他未來的新興瀏覽器在渲染您的頁面時有機會而不會將它們轉移到門外:)

#9


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:

如前所述,我建議實現此目的的最佳方法是使用條件注釋來包含特定於早於8的所有IE版本的樣式表:

<!--[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.

包含的CSS可以設置警告,使其可見或者可以在頁面上啟用“鎖定”用戶的覆蓋。包含一些隱藏頁面上重要元素的規則可能是個好主意,如果用戶不能按預期工作,這些規則可能會使用戶感到困惑。

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.

您是否考慮過為何將大量用戶鎖定在您的網站之外?也許你應該花時間研究如何優雅地降低你的JavaScript,或者相反;使用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.

另一方面,您可以控制組織使用您的站點使用的系統,在這種情況下,您可能可以鎖定人們使用非標准系統。

#10


You can use CSS Conditional Comments

您可以使用CSS條件注釋

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

#11


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

使用javascript,您可以詢問哪個瀏覽器已發送請求>

<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!");
  }
  else
  {
  alert("It's time to upgrade your browser!");
  }
  }
 </script>

#12


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月停用 - 此處提供更多信息。

#13


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.

修復JavaScript,解決問題或優雅降級,以便即使關閉網站也能正常運行。

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並將其粘貼在網站上 - 我聽說它讓你的工作變得像你不相信的那樣。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/05/04/7251ebb4b21709438ffaa5d09188dd21.html



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