如何访问Adobe Air应用程序上的父窗口

如何访问Adobe Air应用程序上的父窗口,adobe,air,parent,Adobe,Air,Parent,以下是在AdobeAIR应用程序中打开窗口的示例代码 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, i

以下是在AdobeAIR应用程序中打开窗口的示例代码

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()">

函数init(){
警报(window.parent);
}
此代码警告空消息;
没有办法访问父窗口吗?

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

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

至少这是总的想法。您可能需要等待htmlDOMCreate或complete事件,然后再设置父级。此外,AIR可能允许您设置父级,即使子级位于另一个安全沙箱中。如果是这样,那将是你应用程序中的一个大安全漏洞。

当你使用createRootWindow()函数时,你会得到一个没有父窗口的窗口——这就是函数名中的“根”试图解决的问题(看起来很糟糕)。不过,解决方法很容易:

win = air.HTMLLoader.createRootWindow(true, init, false, bounds);
win.load(new air.URLRequest(child.url));
//add
win.window.parent = this.window;
至少这是总的想法。您可能需要等待htmlDOMCreate或complete事件,然后再设置父级。此外,AIR可能允许您设置父级,即使子级位于另一个安全沙箱中。如果是这样,那将是你应用程序中的一个大安全漏洞