I want to bounce users of our web site to an error page if they're using a version of Internet Explorer
prior to v9.(如果他们使用的是v9之前的Internet Explorer
版本,我想将我们网站的用户退回至错误页面。)
It's just not worth our time and money to support IE pre-v9
.(支持IE pre-v9
只是不值得我们花费时间和金钱。) Users of all other non-IE browsers are fine and shouldn't be bounced.(使用其他所有非IE浏览器的用户都可以使用,不应被退回。) Here's the proposed code:(这是建议的代码:)
if(navigator.appName.indexOf("Internet Explorer")!=-1){ //yeah, he's using IE
var badBrowser=(
navigator.appVersion.indexOf("MSIE 9")==-1 && //v9 is ok
navigator.appVersion.indexOf("MSIE 1")==-1 //v10, 11, 12, etc. is fine too
);
if(badBrowser){
// navigate to error page
}
}
Will this code do the trick?(这段代码会成功吗?)
To head off a few comments that will probably be coming my way:(首先,我将发表一些评论:)
Yes, I know that users can forge their useragent
string.(是的,我知道用户可以伪造他们的useragent
字符串。) I'm not concerned.(我不在意)
Yes, I know that programming pros prefer sniffing out feature-support instead of browser-type but I don't feel this approach makes sense in this case.(是的,我知道编程专家更喜欢嗅探功能支持而不是浏览器类型,但是在这种情况下,我认为这种方法不可行。) I already know that all (relevant) non-IE browsers support the features that I need and that all pre-v9 IE
browsers don't.(我已经知道所有(相关)非IE浏览器都支持我需要的功能,而所有pre-v9 IE
浏览器均不支持。) Checking feature by feature throughout the site would be a waste.(在整个站点中逐个功能地检查将是浪费。)
Yes, I know that someone trying to access the site using IE v1
(or >= 20) wouldn't get 'badBrowser' set to true and the warning page wouldn't be displayed properly.(是的,我知道尝试使用IE v1
(或> = 20)访问该网站的人不会将'badBrowser'设置为true,并且警告页面将无法正确显示。) That's a risk we're willing to take.(这是我们愿意承担的风险。)
Yes, I know that Microsoft has "conditional comments" that can be used for precise browser version detection.(是的,我知道Microsoft具有可用于精确浏览器版本检测的“条件注释”。) IE no longer supports conditional comments as of IE 10
, rendering this approach absolutely useless.(从IE 10
,IE不再支持条件注释,从而使此方法绝对无用。)
Any other obvious issues to be aware of?(还有其他明显的问题要注意吗?)
ask by Chad Decker translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…