Sti*_*ian 5 javascript google-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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1768 次 |
| 最近记录: |