使用 RegEx 检测 WebKit 版本 525 及更低版本

发布于 2024-08-30 20:54:21 字数 508 浏览 7 评论 0原文

我真的不擅长正则表达式!

我想专门检测版本 525 以下的 WebKit 浏览器。

我有一个正则表达式 [/WebKit/[\d.]+/.exec(navigator.appVersion)] 可以正确返回 WebKit /5….…,真的,我希望它只返回版本号,但如果浏览器不是 WebKit,则返回 null,或者更好的是 0

例如,如果浏览器是 Trident、Presto 或 Gecko,则返回 null,而如果浏览器是 WebKit,则返回其版本号。

为了澄清,我希望正则表达式检查 navigator.appVersion 是否包含 WebKit ,如果不包含,则返回 null,如果包含,则返回版本号。

我感谢您的所有帮助!

请让我们保持专注,不要与 jQuery 或其他类型调情,在这种情况下它太过分了。

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 navigator.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云朵有点甜 2024-09-06 20:54:21

我对此提供了通常的警告:只有当您完全确定没有办法测试您想要使用的 WebKit 版本之间不同的实际功能时,您才应该使用它:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文