我在我的网站中有一个聊天机器人,它需要最新版本的浏览器才能完美地工作,因此我需要向用户显示一条消息,提示他们“请更新您的浏览器到最新版本”。我不想使用第三方插件。如何使用这个js代码,在用户使用不支持的浏览器版本时显示一个div。
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