2013-02-11 82 views
0

如果用戶從舊瀏覽器訪問我網站上的任何頁面,我想爲用戶顯示定製的「升級瀏覽器」模式對話框。在每個頁面上顯示'升級瀏覽器'模式

我知道如何檢測瀏覽器,但 - 我不知道在哪裏放置代碼來顯示模式,以及如何做到這一點。 ApplicationController before_filter可以呈現一個調用.modal('show')的js嗎?任何其他方式?純js?

回答

0

放置DIV /模態在佈局文件(應用程序/視圖/佈局/ application.html.erb,最有可能的),並在鐵軌把它包裝條件根據您的需求,像這樣:

<body> 
    .... 
    <% if (old_browsers.include?(current_browser) %> 
     <div class="old-browser-modal"> 
      .... 
     </div> 
    <% end %> 
</body> 
+0

謝謝,但我在哪裏打電話modal.show ?如果每個page.load條件? – anu 2013-02-11 22:24:01

2

這將最適合使用Javascript解決。

  • 檢測需要使用Modernizr的
  • 如果Modernizr的測試失敗的瀏覽器功能,顯示某種

的酥料餅添加modernizr.js到您的項目,並插入這個JavaScript到您的應用程序。 js:

Modernizr.load([ 
    { 
     test: Modernizr.cssgradients, 
     nope: function() { alert('Sorry, your browser does not support a required feature of this site. Please upgrade or use another browser.'); } 
    } 
]); 

將「Modernizr.cssgradients」更改爲您需要的任何功能。

如果你不希望有此作爲裸「警報」,你可以使用類似noty.js,以取代上述alert方法:

noty({text: 'Sorry, your browser does not support a required feature of this site. Please upgrade or use another browser.'}); 
+0

謝謝你的幫助。我想在自己的網站上使用引導模式來保持其他模式的一致性。我會檢查Modernizr。 – anu 2013-02-11 22:23:09

+0

當然 - 有一個Bootstrap模式可以滿足你的需求。 – stef 2013-02-13 12:30:51

相關問題