开发者

Detect WebKit Version 525 and Below With RegEx

开发者 https://www.devze.com 2022-12-29 01:43 出处:网络
I\'m no good at Regular Expressions, really! I would like to specifically detect WebKit browsers below version 525.

I'm no good at Regular Expressions, really!

I would like to specifically detect WebKit browsers below version 525.

I have a regular expression [/WebKit/[\d.]+/.exec(navigator.appVersion)] that correctly returns WebKit/5….…, really, I'd like it to return only the version number, but if the browser isn't WebKit, return null, or better still 0.

For example, if the browser was Trident, Presto or Gecko, return null, whereas if the browser is WebKit, return it's version number.

To clarify, I would like the regular expression to check if navig开发者_如何转开发ator.appVersion contains WebKit and if it does not, return null, if it does, return the version number.

I appreciate all your help!

Please let's keep this focused, let's not flirt with jQuery or the sort, it's overkill in this scenario.


I'm providing this with the usual caveats: you should use this only if you are absolutely sure there is no way to test the actual feature you want to use that differs between WebKit versions:

function checkWebKit() {
    var result = /AppleWebKit\/([\d.]+)/.exec(navigator.userAgent);
    if (result) {
        return parseFloat(result[1]);
    }
    return null;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消