-3

我的网站应该只适用于 IE8 和更高版本。如何将使用开发人员工具的版本更改限制为用户使用?有没有办法使用 Jquery 来限制它?

这是我的 javascript 来找出用户代理的浏览器模式和文档模式,但我不限制用户将浏览器和文档模式更改为 IE7。

<script type="text/javascript">
/*
* Author: Rob Reid
* CreateDate: 20-Mar-09
* Description: Little helper function to return details about IE 8 and its various compatibility settings either use as it is
* or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is
* very common so use with caution.
*/
$(function(){
var browserInfo = IEVersion();
console.log($('meta'));
  alert(browserInfo.DocMode);
  $('meta').attr('rel','IE=7');
});
function IEVersion()
{
    var _n = navigator, _w = window, _d = document;
    var version = "NA";
    var na = _n.userAgent;
    var ieDocMode = "NA";
    var ie8BrowserMode = "NA";
    // Look for msie and make sure its not opera in disguise
    if (/msie/i.test(na) && (!_w.opera))
    {
        // also check for spoofers by checking known IE objects
        if (_w.attachEvent && _w.ActiveXObject)
        {
            // Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
            version = (na.match(/.+ie\s([\d.]+)/i) || [])[1];
            // Its IE 8 pretending to be IE 7 or in compat mode              
            if (parseInt(version) == 7)
            {
                // documentMode is only supported in IE 8 so we know if its here its really IE 8
                if (_d.documentMode)
                {
                    version = 8; //reset? change if you need to
                    // IE in Compat mode will mention Trident in the useragent
                    if (/trident\/\d/i.test(na))
                    {
                        ie8BrowserMode = "Compat Mode";
                        // if it doesn't then its running in IE 7 mode
                    } else
                    {
                        ie8BrowserMode = "IE 7 Mode";
                    }
                }
            } else if (parseInt(version) == 8)
            {
                // IE 8 will always have documentMode available
                if (_d.documentMode) { ie8BrowserMode = "IE 8 Mode"; }
            }
            // If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions                         
            ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode == "CSS1Compat") ? 7 : 5; //default to quirks mode IE5                                                                      
        }
    }

    return {
        "UserAgent": na,
        "Version": version,
        "BrowserMode": ie8BrowserMode,
        "DocMode": ieDocMode
    }
}

function DisplayInfo()
{
    var browserInfo = IEVersion();
    alert('UserAgent: ' + browserInfo.UserAgent + '\nVersion: ' + browserInfo.Version + '\nBrowserMode: ' + browserInfo.BrowserMode + '\nDocMode: ' + browserInfo.DocMode);
}

4

3 回答 3

1

尽量不要这样做,因为这会惹恼许多可能的用户并迫使他们访问竞争对手的网站。

诚然,例如,如果您使用 ActiveX 控件,您可能无法对选择的浏览器做太多事情。

于 2013-07-04T14:40:06.963 回答
0

You can use some Conditional comments like thus:

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

You can find more about this here

于 2013-07-04T14:37:33.907 回答
0

如何使用jquery限制它

只是不可能。不管是好习惯还是坏习惯。您只是不能通过 jQuery 或 Javascript 更改浏览器设置。

当用户尝试使用开发人员工具更改版本时

我认为您可以做的是将此元标记用作 head 内的第一个标记:

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

这将迫使 IE 退出兼容模式并使用最新版本,无论它是什么。

当您使用像 ASP.Net 这样的服务器端框架时,您不能确定这将保留为 head 中的第一个标记。因此,例如在 ASP.Net 中,您可以在 PreInit 中编写:

HttpContext.Current.Response.AddHeader("X-UA-Compatible", "IE=Edge")

或者,您也可以从 Web 服务器(例如 IIS)推送标头。

于 2013-07-04T15:02:32.260 回答