Modify Javascript checking browser version

bfuchs
bfuchs used Ask the Experts™
on
Hi Experts,

I have the following code that checks if users have the latest and supported browser version (for Caspio apps).

<script src="//cdnjs.cloudflare.com/ajax/libs/bowser/1.9.4/bowser.min.js" integrity="sha256-tS9rYBF0HnbO+ivkEWS7ybM7ujNLmtFbA6utN7YJ2YM=" crossorigin="anonymous"></script>
<script>
    // alert(JSON.stringify(bowser)); // uncomment this to know what bowser get from your browser to use it below
    var version = bowser.version.match(/\d*\.{0,1}\d+/).pop() * 1
    var ua = window.navigator.userAgent;
    if(/Edge/.test(ua)) {
        if(parseInt(ua.substring(ua.indexOf('Edge/') + 5, ua.indexOf('.', ua.indexOf('Edge/'))))<12)
            alert("your edge version need to be over 12")
    }
    else if(bowser.msie) {
        if(version<11)
            alert("your internet explorer version need to be over or equal to 11");
    }
    else if(bowser.chrome) {
        if(version<=70)
            alert("your chrome version need to be over 70");
    }
    else if(bowser.firefox) {
        if(version<=65)
            alert("your firefox version need to be over 65");

    }
    else alert("your browser is not supported");
</script>

Open in new window


Would like to remove Edge and add Safari latest version to it.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

That would be something like this
I also fix your code you forgot the = sign for msie

For the other you may change the message to equal or over or remove the = if you want only over it's up to you
depending of the needs you will remove the = or change the message accordingly

var version = bowser.version.match(/\d*\.{0,1}\d+/).pop() * 1
    var ua = window.navigator.userAgent;
   
    
    if(bowser.msie) {
        if(version<=11)
            alert("your internet explorer version need to be over or equal to 11");
    }
    else if(bowser.chrome) {
        if(version<=70)
            alert("your chrome version need to be over 70");
    }
    else if(bowser.firefox) {
        if(version<=65)
            alert("your firefox version need to be over 65");
    }
    else if(bowser.safari) {
        if(version<=9)
            alert("your Safari version need to be over 9");
    }
    else  { alert("your browser is not supported"); }

Open in new window


You can read instructions https://github.com/lancedikson/bowser#filtering-browsers
Hi lenatml,

Two questions.

How do I know which is the latest version of Safari?

in Google i see the following.

Operating system      Operating system version      Latest Safari version
macOS      Mac OS X 10.2 Jaguar      1.0.3 (August 13, 2004)
Mac OS X 10.3 Panther      1.3.2 (January 11, 2006)
Mac OS X 10.4 Tiger      4.1.3 (November 18, 2010)
Mac OS X 10.5 Leopard      5.0.6 (July 20, 2011)

While here I see up to version 12.

I also fix your code you forgot the = sign for msie
Why is the original code not okay, as the latest is version 11, no?

Thanks,
Ben
On one of my device I have Safari 12.1
So yes it may depend of the device mobile or desktop / and OS

So you can check version per device with your script
refer to the link I provide for instruction
 https://github.com/lancedikson/bowser#filtering-browsers

// per platform (mobile, desktop or tablet)
  mobile: {
    safari: '>=9',
    'android browser': '>3.10'
  },

Open in new window


I would not check for the latest version as it change rapidly and often but instead since a version you know it is compatible
<= x version

You can check from this site about compatibility
https://caniuse.com/

So base on caniuse here are the current version
Chrome 76
Firefox 68
Safari 12.1
Edge 18
Thank you!
Hi Lenamtl,

Tested the following portion of the code with user having version 67 and no alert popped up.

else if(bowser.firefox) {
        if(version<70)
            alert("your firefox version need to be over 65");
    }

Open in new window


See attached.

Thanks,
Ben
Capture.PNG

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial