轉載自:http://blog.csdn.net/vking_wang/article/details/11659725
問題
前些天遇到了一個神奇的問題:有個網頁包含了iframe,之前一直運行良好,但是Firefox升級到最新的23.0版本後,發現iframe內的內容變成空的了!查看元素iframe裏只有。其他瀏覽器都沒有問題。
原因
stackoverflow上有人說是因爲使用了樣式display:none;的緣故:
In google chrome the div contains an inline style of display:block (and a background-image). But in firefox the div it doesn’t have the display:block (only the background image). So, the problem is that teir scripts are not “showing” the map’s div.
see http://stackoverflow.com/questions/13790728/iframe-not-working-in-firefox
查了iframe src引用的網頁源碼,確實有這個樣式!但是,把它去掉後,問題依舊。。。
後來偶然發現控制檯上有打印:
[plain] view plain copy print?
已阻止讀取混合活動內容 “http://10.235.59.215:8888/…….”
google之後發現Firefox23默認阻止讀取混合活動內容!see Mixed Content Blocking Enabled in Firefox 23!
那麼什麼是混合活動內容呢?當一個HTTPS頁面中包含HTTP內容時,即使主頁面是經過SSL加密受HTTPS協議保護,但其中的HTTP內容可以被攻擊者閱讀或更改;這種HTTPS頁面包含HTTP內容的情況,就被稱爲“混合內容”。
這種內容是不安全的,如果主頁面是HTTPS,但iframe src引用HTTP內容,Firefox23默認會阻止這種內容的顯式!
解決方案1
最直接的解決方法就是避免這種混合內容,將iframe src改爲HTTPS即可。
解決方案2
但iframe引用的頁面不支持HTTPS怎麼辦?可以讓Firefox暫時不阻止:
點擊地址欄的盾牌圖標,選擇Disable Protection on This Page;就會顯示iframe;之後這個盾牌圖標會變成一個感嘆號圖標。
解決方案3
但上述方案只對當前session有效,重啓瀏覽器後又會被阻止。要讓Firefox默認不阻止:
地址欄輸入about:config進入配置頁面,找到security.mixed_content.block_active_content,把它設爲false。