Discover WebKit version 525 and below with RegEx

I am not very good at regular expressions!

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

I have a regular expression [ /WebKit/[\d.]+/.exec(navigator.appVersion) ] that correctly returns WebKit/5….… really, I would like it to return only the version number, but if the browser is not 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 its version number.

To clarify, I would like the regular expression to check if navigator.appVersion contains WebKit , and if not, return zero, if so, return the version number.

I appreciate all your help!

Please keep it focused, let it not flirt with jQuery or sort, it digests in this scenario.

+4
source share
1 answer

I provide this with the usual caveats: you should use this only if you are absolutely sure that there is no way to test the actual function that you want to use, which differs between versions of WebKit:

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

Source: https://habr.com/ru/post/1308298/


All Articles