2017-02-23 86 views
0

我使用reactjs和webpack创建了一个网站,我使用modernizr来显示对特定功能的支持,但我想在IE 8和以下版本中显示一条消息,表示我不支持这些浏览器。问题是当加载网站时,它会失败,因为webpack和反应不支持它。 我的问题是,我如何显示消息?有什么方法可以在反应加载之前显示它?或者可能有一种方法可以让它为那个消息工作?无法显示IE 8和关闭不支持消息

感谢您的帮助!

回答

3

您可以使用条件注释来加载特殊CSS并仅在IE8中打印HTML。

http://www.quirksmode.org/css/condcom.html

例子:

<!--[if lte IE 8]> 
<p class="unsupported-ie">This page is not supported for IE8 and lower versions of IE.</p> 
<![endif]--> 

而且你可以在<head>即使负载CSS:

<!--[if lte IE 8]> 
<link media="all" rel="stylesheet" href="/unsupported-ie.css" /> 
<![endif]--> 
+0

+包括应用JS在“GTE IE 9”和/或“不是IE”条件注释所以它甚至不必须下载。 – pawel

+0

这实际上很好吃,是否有像这样的其他浏览器btw的解决方案? IE是我的主要问题,但可以说,有没有一种方法来制定一个条件,不具体说IE X? –

+0

我不这么认为,甚至更新的IE不支持它(从官方文档:*从Internet Explorer 10开始,标准模式不再支持条件注释。使用功能检测为网站功能提供有效的回退策略, t由浏览器支持。有关标准模式的更多信息,请参阅定义文档兼容性*)。但是,您可以使用它没有任何问题,因为IE版本9以下。 –

0

请检查这一点,我用简单的Java脚本识别浏览器&及其version.A弹出消息将出现,并将提供适当的消息 - 如果版本兼容,然后加载站点,否则停止从出发ahead- 以下用户是简单的HTML页面: -

<!DOCTYPE html> 
<html> 
<head> 
    <style> 
       .modal { 
      display: none; /* Hidden by default */ 
      position: fixed; /* Stay in place */ 
      z-index: 1; /* Sit on top */ 
      padding-top: 100px; /* Location of the box */ 
      left: 0; 
      top: 0; 
      width: 100%; /* Full width */ 
      height: 100%; /* Full height */ 
      overflow: auto; /* Enable scroll if needed */ 
      background-color: rgb(0,0,0); /* Fallback color */ 
      background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ 
     } 

     /* Modal Content */ 
     .modal-content { 
      background-color: #fefefe; 
      margin: auto; 
      padding: 20px; 
      border: 1px solid #888; 
      width: 80%; 
     } 

     /* The Close Button */ 
      .close { 
       color: #aaaaaa; 
       float: right; 
       font-size: 28px; 
       font-weight: bold; 
       } 

      .close:hover, 
      .close:focus { 
       color: #000; 
       text-decoration: none; 
       cursor: pointer; 
      } 
    </style> 
</head> 
<body onload="IEValidationMessage();"> 

    <!-- this is the DIV used for showing message box --> 
    <div id="myModal" class="modal"> 
     <div id="closeBtn" class="modal-content"> 
      <span class="close">&times;</span> 
      <div id="divMessagebody"></div> 
     </div> 
    </div> 

    <script> 
     // When the user clicks on <span> (x), close the modal 
     var modal = document.getElementById('myModal'); 
     var span = document.getElementById("closeBtn"); 
      span.onclick = function() { 
      modal.style.display = "none"; 
     } 
     // When the user clicks anywhere outside of the modal, close it 
      window.onclick = function (event) { 
      if (event.target == modal) { 
      modal.style.display = "none"; 
      } 
     } 
     function IEValidationMessage() { 
      modal.style.display = "block"; 
      if (document.documentMode < 9) { 
       document.getElementById("divMessagebody").innerHTML = "Please Use IE 9 or Above.)"; 
      } 
      else { 
      document.getElementById("divMessagebody").innerHTML = "congrats Site is compatible in this IE version "; 
     } 
     if (document.documentMode ==undefined) { 
      document.getElementById("divMessagebody").innerHTML = "Please use IE9 or higher only. "; 
     } 
    } 

    </script> 

    </body>