简体   繁体   English

我的firefox浏览器测试出了什么问题?

[英]What is wrong with my firefox browser test?

I want to test if the user is using Firefox under version 3.0, if yes trigger the function and here's what I ended up with! 我想测试用户是否正在使用3.0版以下的Firefox,如果可以,则触发该功能,这就是我最终得到的结果! Now I use the version 14.0 of Firefox to test it out and it still trigger the function! 现在,我使用Firefox 14.0版本对其进行测试,它仍会触发该功能! Anyone can help a beginner? 任何人都可以帮助初学者吗? Thanks! 谢谢!

script: 脚本:

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
var ffversion= Number(RegExp.$1) // capture x.x portion and store as a number
if (ffversion<=3)
{ 

Here: 这里:

var result = /Firefox[\/\s](\d+\.\d+)/.exec( navigator.userAgent );

if ( result && +result[1] <= 3 ) {
    // do your thing 
}

Note that feature testing would make a better solution: 请注意,功能测试将提供更好的解决方案:

if ( browser_doesnt_implement_this_feature ) {
    implementIt();
}

You could just do it in one regex test: 您可以在一个正则表达式测试中做到这一点:

if(/Firefox[\/\s]([0-2]\.|3\.0)/g.test(navigator.userAgent)){
  // do old FF stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM