如何访问 Adob​​e Air Apps 上的父窗口

发布于 2024-10-08 21:47:49 字数 560 浏览 0 评论 0原文

以下是在 Adob​​e 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-10-15 21:47:49

当您使用 createRootWindow() 函数时,您会得到一个没有父窗口的窗口 - 这就是函数名称中的“Root”试图传达的内容(看起来很糟糕)。不过,解决方法很容易:

win = air.HTMLLoader.createRootWindow(true, init, false, bounds);
win.load(new air.URLRequest(child.url));
//add
win.window.parent = this.window;

至少这是总体思路。在设置父级之前,您可能需要等待 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:

win = air.HTMLLoader.createRootWindow(true, init, false, bounds);
win.load(new air.URLRequest(child.url));
//add
win.window.parent = this.window;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文