简体   繁体   中英

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! Now I use the version 14.0 of Firefox to test it out and it still trigger the function! 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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