开发者

How to access a parent window on Adobe Air Apps

Following is a sample code for opening a window in Adobe Air App.

var init = new air.Nat开发者_高级运维iveWindowInitOptions();
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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜