我正在开发一个.net项目,我正在使用jquery创建一个弹出窗口,如下所示:
var newWindow = window.open("", id, "resizable=1,status=0,menubar=0,toolbar=0,location=0,top=0,left=0");
然后我在其中注入html文档,
newWindow.document.write("<!doctype html>" +
"<html>" +
"<head>" +
"<title>" + id + "</title>" +
"<link href='" + css + "' type='text/css' rel='stylesheet' />" +
"<script src= '/Scripts/d3.min.js' ><\/script/>" +
"<script src= '/Scripts/myScript.js' ><\/script/>" +
"</head>" +
"<body></body>" +
"</html>");
myScript.js中有一些代码使用d3并绘制一些SVG内容。 我将绘图函数称为如下:
$(newWindow.document).ready(function () {
newWindow.DrawSvg();
}
然而,d3未定义的抛出错误。 看起来,当我调用绘图函数时,d3.min.js没有加载它仍然加载。
我的问题是,如何确保我的子窗口完成加载依赖项?它看起来像$(newWindow.document).ready已经不是很有效了!
此外: 有趣的是,newWindow.DrawSvg()似乎只在IE中工作。 在firefox和chrome中,DrawSvg返回以下错误:
Uncaught TypeError: newWindow.DrawSvg() is not a function
看起来javascript功能尚不可用。 我尝试连接一个计时器,在500毫秒后触发该调用,但它不起作用。
感谢。
答案 0 :(得分:1)
尝试这个家伙做的事:Waiting for child window loading to complete
基本上:
var newWindow = window.open('child.html')
newWindow.addEventListener('load', newWindow.document.write(...), true);
newWindow.addEventListener('load', runAJAXhere, true);
等