I know this is not the most reliable way, but I don't really have many other choices. I essentially need to detect what browser and version visits my website. If it is a certain browser/version, it will display a message. This is for the TLS issue, whereby certain browser versions will not display a https page.
Anyways, at the moment I have something like the following
function getBrowserInfo()
{
var ua = navigator.userAgent, tem,
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1]))
{
tem= /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome')
{
tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
M = M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/(\d+)/i))!= null)
M.splice(1, 1, tem[1]);
return M.join(' ');
}
var browserInfo = getBrowserInfo();
browserInfo = browserInfo.split(" ");
$(function () {
alert(browserInfo);
if(browserInfo[0] == 'Firefox' && browserInfo[1] < 27) {
alert("Firefox");
}
if(browserInfo[0] == 'Chrome' && browserInfo[1] < 22) {
alert("Chrome");
}
if(browserInfo[0] == 'IE' && browserInfo[1] < 11) {
alert("IE");
}
if(browserInfo[0] == 'Safari' && browserInfo[1] < 11) {
alert("Safari");
}
if(browserInfo[0] == 'Opera' && browserInfo[1] < 14) {
alert("Safari");
}
});
One thing that concerns me is the splitting of the string, incase a browser returns a different format. Additionally, I think all of these if statements are redundant, but I cant think of a more efficient way to do this.
Essentially, I am looking for advice as to the best way to detect a browser, and its version, so I can display a custom message for that browser.
Thanks