使用Internet Explorer时始终显示更新通知

问题描述

我刚刚发现这个handy site可以向用户显示更新浏览器的通知,如果它们已经过时,但是在mi网站上,我需要使用HTML 5,而Internet Explorer不支持

是否有人知道使用Internet Explorer时是否可能始终显示通知,但允许其他浏览器上的提醒冷却时间?

到目前为止,我的代码是:

    var $buoop = {required:{e:-4,f:-3,o:-3,s:-1,c:-3},insecure:true,unsupported:true,api:2020.08,text_for_i: {
        'msg':'Tu navegador {brow_name} ya no es soportado.','msgmore': 'Por favor utiliza otro navegador para poder usar nuestro sitio.'
     } };
    function $buo_f(){
     var e = document.createElement("script");
     e.src = "//browser-update.org/update.min.js";
     document.body.appendChild(e);
    };
    try {document.addEventListener("DOMContentLoaded",$buo_f,false)}
    catch(e){window.attachEvent("onload",$buo_f)}

解决方法

根据您的描述,看起来用户是否正在使用任何版本的IE浏览器,那么您希望向用户显示使用其他任何浏览器的通知。

我建议您参考下面的示例,它可以帮助您获得所需的结果。

<!doctype html>
<html>
   <head>
      <script> 
         //detects if user uses Internet Explorer 
         //returns version of IE or false,if browser is not IE 
         //Function to detect IE or not 
         function IEdetection() { 
             var ua = window.navigator.userAgent; 
             var msie = ua.indexOf('MSIE '); 
             if (msie > 0) { 
                 // IE 10 or older,return version number 
                 return ('Tu navegador IE ' + parseInt(ua.substring( 
                   msie + 5,ua.indexOf('.',msie)),10) + ' ya no es soportado. Por favor utiliza otro navegador para poder usar nuestro sitio.'); 
             } 
             var trident = ua.indexOf('Trident/'); 
             if (trident > 0) { 
                 // IE 11,return version number 
                 var rv = ua.indexOf('rv:'); 
                 return ('Tu navegador IE ' + parseInt(ua.substring( 
                   rv + 3,rv)),10) + ' ya no es soportado. Por favor utiliza otro navegador para poder usar nuestro sitio.'); 
             } 
            
             // User uses other browser 
             return ('Welcome...'); 
         } 
         var result = IEdetection(); 
         document.write(result); 
         
         
      </script>
   </head>
   <body>
      <h2>Test page...</h2>
   </body>
</html>

在IE浏览器中的输出:

enter image description here

参考:

How to check the user is using Internet Explorer in JavaScript?