bfuchs
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).
Would like to remove Edge and add Safari latest version to it.
Thanks
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>
Would like to remove Edge and add Safari latest version to it.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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'
},
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
ASKER
Thank you!
ASKER
Hi Lenamtl,
Tested the following portion of the code with user having version 67 and no alert popped up.
See attached.
Thanks,
Ben
Capture.PNG
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");
}
See attached.
Thanks,
Ben
Capture.PNG
ASKER
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.
Why is the original code not okay, as the latest is version 11, no?
Thanks,
Ben