我开发了一个函数,调用时应该打开一个窗口,但它会返回null
。如果我在原始 JavaScript 函数中打开窗口,它就可以工作。我想它是将控制权传递给另一个函数的原始函数,但由于某种原因这不起作用。
这是我的原始函数,这基本上调用了一个新的 JavaScript 文件并加载了一个 HTML 文件,当“就绪”时,它需要显示 window.open 以及现在为字符串形式的 HTML 文件。
order.prototype.printMe = function() {
order_resume.loadthis("myTestPage.html", "showData");
// OPENING WINDOW HERE WORKS; but the the html file that is loaded
// in above line hasn't finsihed loading - so i need to show it form
// the function below once in "ready" state
/* child1 = window.open ("about:blank","_blank");
child1.document.write( myDocument );
child1.document.close();
*/
}
这是我从原始函数调用的函数:
function showResume() {
this.req = false;
reservaResumen.prototype.showData = function() {
if (this.req.readyState == 4) {
child1 = window.open("about:blank", "_blank"); /// THIS RETURNS NULL
child1.document.write("test");
child1.document.close();
}
}
reservaResumen.prototype.loadthis = function(url, myMethod) {
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
this.req = new XMLHttpRequest();
}
catch (e) {
this.req = false;
}
}
else if (window.ActiveXObject) {
try {
this.req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
this.req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
this.req = false;
}
}
}
if (this.req) {
var loader = this;
this.req.onreadystatechange = function() {
eval("loader." + myMethod + ".call(loader)")
}
this.req.open("GET", url, true);
this.req.send("");
}
}