如何访问 Adobe Air Apps 上的父窗口
以下是在 Adobe Air App 中打开窗口的示例代码。
var init = new air.NativeWindowInitOptions();
var bounds = null;
var child = air.File.applicationDirectory.resolvePath('child.html');
bounds = new air.Rectangle(0, 0, 300, 500);
win = air.HTMLLoader.createRootWindow(true, init, false, bounds);
win.load(new air.URLRequest(child.url));
打开的窗口必须访问父窗口的文档对象。 以下是child.html的代码,
<script>
function init() {
alert(window.parent);
}
</script>
<body onload="init()">
该代码警告空消息; 有没有办法访问父窗口?
Following is a sample code for opening a window in Adobe Air App.
var init = new air.NativeWindowInitOptions();
var bounds = null;
var child = air.File.applicationDirectory.resolvePath('child.html');
bounds = new air.Rectangle(0, 0, 300, 500);
win = air.HTMLLoader.createRootWindow(true, init, false, bounds);
win.load(new air.URLRequest(child.url));
A opened window must access document object of a parent window.
Following is a code of child.html
<script>
function init() {
alert(window.parent);
}
</script>
<body onload="init()">
this code alerts null message;
Is there no way to access a parent window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 createRootWindow() 函数时,您会得到一个没有父窗口的窗口 - 这就是函数名称中的“Root”试图传达的内容(看起来很糟糕)。不过,解决方法很容易:
至少这是总体思路。在设置父级之前,您可能需要等待 htmlDOMCreate 或complete 事件。此外,即使子级位于另一个安全沙箱中,AIR 也可能允许您设置父级。如果是这样,那将是您的应用程序中的一个很大的安全漏洞。
When you use the createRootWindow() function, you get a window without a parent -- that's what the "Root" in the function name is trying to get across (poorly, it seems). It is easy to workaround, though:
At least that's the general idea. You might need to wait for the htmlDOMCreate or complete event before setting the parent. Also, AIR might let you set the parent even if the child is in another security sandbox. If so, that would be a big security hole in your app.