【发布时间】:2011-03-10 03:48:41
【问题描述】:
以下 javascript 导致 Internet Explorer 发出“混合内容”警告:
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// kill the timer
if (_timer) clearInterval(_timer);
// do stuff
};
/* for Mozilla/Opera9 */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
init(); // call the onload handler
}
};
/*@end @*/
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
init(); // call the onload handler
}
}, 10);
}
/* for other browsers */
window.onload = init;
用于检测 DOM 何时完成加载。此脚本中的什么内容会导致混合内容警告?
【问题讨论】:
-
其原因在dean.edwards.name/weblog/2006/06/again 讨论(此代码来自哪里)
-
我同意 Cresent。这类似于在通过 https 传递的页面上创建 about:blank IFRAME。 src 必须引用 https 上的某些内容以确保安全。
-
在这个时代,你为什么还要使用这种技巧?
-
我正在使用 Magento GO 托管解决方案,上传 jQuery 库会导致 Magento 模板的功能停止工作(大部分 ui 交互性/等等)。有没有更好的方法来检查DOM 使用不同的方法加载了 jQuery?
-
已解决 - 对于任何试图在 Magento GO 模板中使用 jQuery 库的人,您必须在 jQuery 库的末尾调用 jQuery.noConflict()。在以后的 js 文件中调用它不会成功:)
标签: javascript internet-explorer dom ssl https