问题描述
我正在开发一个使用windows.open(..)打开弹出窗口的Web应用程序。我需要使用由window.open返回的句柄在打开的窗口上调用函数,但是我总是收到错误消息addWindow.getMaskElements不是函数,就好像它无法访问声明的函数在儿童窗口。这是IE和FF的行为。我的代码如下所示:
函数AddEmail(目标,类别)
{
if(addWindow = = null)
{
currentCategory = category;
var left = getDialogPos(400,220)[0];
var top = getDialogPos(400,220)[1];
addWindow = window.open(adicionar_email.htm,null,height = 220px,width = 400px,status = no,resizable = no);
addWindow.moveTo(left,top);
addWindow.getMaskElements();
}
}
我已经从不同的可靠来源读取并读取显然这应该是可行的,但事实并非如此。
还有一点,子窗口中的函数在adicionar_email.htm文件中包含的单独的.js文件中声明。这是否有所作为?它不应该..
所以,如果有人遇到过类似的问题,或者对我做错了什么有所了解,请回复此消息。
提前致谢。
Kenia
窗口创建不是阻塞操作;脚本继续执行,同时该窗口打开并加载HTML& javascript和解析它。
如果您要在原始页面上添加链接,请执行以下操作:
< a href =#onclick =addWindow.getMaskElements();>测试< / a>
你会看到它的工作原理。 (我试了一下就可以了。)
**编辑**
其他人发布了一个解决方法通过调用目标文档中的onload,以下是另一种方法:
$ p $ function AddEmail()
{
if(addWindow == null){
addWindow = window.open(test2.html,null,height = 220px,width = 400px,status = no,resizable = no); $!
$ b if(!addWindow.myRemoteFunction){
setTimeout(AddEmail,1000);
} else {addWindow.myRemoteFunction(); }
}
这会一直试图每隔1秒调用一次addWindow.myRemoteFunction,成功地称呼它。
I'm developing a web application that opens a popup using windows.open(..). I need to call a function on the opened window using the handle returned by "window.open", but I'm always getting the error message "addWindow.getMaskElements is not a function", as if it couldn't access the function declared on child window. This is the behavior in both IE and FF. My code looks like this:
function AddEmail(target,category)
{
if(addWindow == null)
{
currentCategory = category;
var left = getDialogPos(400,220)[0];
var top = getDialogPos(400,220)[1];
addWindow = window.open("adicionar_email.htm",null,"height=220px, width=400px, status=no, resizable=no");
addWindow.moveTo(left,top);
addWindow.getMaskElements ();
}
}
I've googled and read from different reliable sources and apparently this is supposed to work, however it doesn't.One more thing, the functions in child window are declared in a separate .js file that is included in the adicionar_email.htm file. Does this make a difference? It shouldn't..So, if anyone has ran into a similar problem, or has any idea of what I'm doing wrong, please, reply to this message.Thanks in advance.
Kenia
The window creation is not a blocking operation; the script continues to execute while that window is opening and loading the HTML & javascript and parsing it.
If you were to add a link on your original page like this:
<a href="#" onclick="addWindow.getMaskElements();">Test</a>
You'd see it works. (I tried it just to be sure.)
**EDIT **
Someone else posted a workaround by calling an onload in the target document, here's another approach:
function AddEmail()
{
if(addWindow == null) {
addWindow = window.open("test2.html",null,"height=220px, width=400px, status=no, resizable=no");
}
if(!addWindow.myRemoteFunction) {
setTimeout(AddEmail,1000);
} else { addWindow.myRemoteFunction(); }
}
This keeps trying to call addWindow.myRemoteFunction every 1 second til it manages to sucessfully call it.
这篇关于从opener调用子窗口函数的JavaScript不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!