Detect unsupported browser version and show specific div with message
12,790
navigator.sayswho = ( function () {
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( ' ' );
} )();
//document.getElementById('printVer').innerHTML=navigator.sayswho
var str = navigator.sayswho;
var browser = str.substring( 0, str.indexOf( " " ) );
var version = str.substring( str.indexOf( " " ) );
version = version.trim();
version = parseInt( version );
console.log( browser );
console.log( version );
if ( ( browser == "Chrome" && version < 70 ) || ( browser == "Firefox" && version < 53 ) || ( browser == "Safari" && version < 5 ) || ( browser == "IE" && version < 11 ) || ( browser == "Opera" && version < 52 ) ) {
$( '#printVer' ).show();
}
else {
$( '#printVer' ).hide();
}
Author by
Dhanil
Updated on June 04, 2022Comments
-
Dhanil almost 2 years
I have a chat bot in my website it need latest version of browsers to work perfectly so I need to show a message to user saying "Please update your browser to latest version". I don't want to use third party plugin. How can i show a div if the user is using unsupported version of browsers using this js code
Html
<div id="printVer"></div>
JS
navigator.sayswho= (function(){ 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(' '); })(); document.getElementById('printVer').innerHTML=navigator.sayswho
-
Zoe stands with Ukraine about 5 years
jquery's $.browser was deprecated in 2009 and removed in 2013. [...]
(from a now deleted answer attempting to reply to this) -
Dendi Handian about 5 yearsis there any javascript package to show alert when the browser is outdated version or unsupported?