Link to home
Start Free TrialLog in
Avatar of bfuchs
bfuchsFlag for United States of America

asked on

Modify Javascript checking browser version

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
ASKER CERTIFIED SOLUTION
Avatar of lenamtl
lenamtl
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bfuchs

ASKER

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
Avatar of bfuchs

ASKER

Thank you!
Avatar of bfuchs

ASKER

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