![](/img/trans.png)
[英]Detect Firefox mixed content blocking with JavaScript or jQuery?
[英]Programmatically detect Mixed Content blocking in Chrome
有沒有人知道是否可以在JavaScript中檢測到Chrome由於混合內容限制而阻止了內容? 我看到控制台中有一條錯誤消息,但這似乎不是一個例外,因為使用try / catch不會捕獲任何內容。
那么問題是,如何檢測內容已被阻止?
謝謝!
我有一個類似的場景,我盲目地嵌入可以在HTTP或HTTPS域上的iframe 。 假設有以下內容,我發現了一個可行的臟方法:
我已對代碼進行了評論,因此很容易理解:
<script type="text/javascript">
$(function () { /* when DOM is fully loaded */
if ("https:" == window.location.protocol)
{ /* we are on the SSL (HTTPS) version of our website */
$.each($("iframe"), function (k, iframe)
{ /* iterate through all iframes */
if ("http:" == $(iframe).attr('src').substring(0, 5))
{ /* there's at least an iframe with non-SSL (HTTP) content (that will be blocked by the browser) */
/* lets redirect user to the non-SSL (HTTP) version of the website */
window.location = window.location.href.replace(/^https:\/\//ig, "http://");
return false;
}
})
}
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.