I am working on a .net project where I am creating a popup window using jquery as follows:
var newWindow = window.open("", id, "resizable=1,status=0,menubar=0,toolbar=0,location=0,top=0,left=0");
Then I am injecting the html document in it,
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>");
There is some code in myScript.js that uses d3 and draw some SVG stuff. I call that draw function as follows:
$(newWindow.document).ready(function () {
newWindow.DrawSvg();
}
However, it is throwing error that d3 is undefined. It looks like, d3.min.js is not loading it still loading when I am calling that draw function.
My question is, how can I make sure that my child window is done finished loading the dependencies? it looks like $(newWindow.document).ready is not quite doing the trick!
ADDITION: Interestingly, newWindow.DrawSvg() seems to work only in IE. In firefox and chrome, DrawSvg return following error:
Uncaught TypeError: newWindow.DrawSvg() is not a function
It looks like the javascript function is not available yet. I tried to attach a timer to trigger that call after 500 ms, it didn't work.
Thanks.