【发布时间】:2009-05-13 10:49:55
【问题描述】:
我开发了一个函数,调用时应该打开一个窗口,但它返回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("");
}
}
【问题讨论】:
-
是否启用了弹出窗口拦截器?
-
否 - 因为它在原始函数中打开它..
-
请仔细检查弹出窗口阻止程序设置。浏览器不会在没有用户交互的情况下打开窗口。此外,当用户这样做时,例如。单击操作,但您等待很长时间(例如,通过执行一些异步操作,如 Ajax 请求),浏览器也会阻止窗口并为 window.open 返回 null。
-
不是这样的,因为它在原始函数中打开
-
好的,在重做我的代码后,它完全一样,但正在工作..感谢您的回复..不知道发生了什么!再次感谢
标签: javascript function class dom-events