为帧的 dominitialize 事件指定事件处理函数。该事件是在创建帧的窗口和文档对象之后以及在分析任何脚本或创建文档元素之前引发的特定于 AIR 的事件。 帧会在加载序列中尽早调度 dominitialize 事件,以使子页中的任何脚本均可引用由 dominitialize 处理函数添加到子文档的对象、变量和函数。父页必须与子页位于相同沙箱中才能直接添加或访问子文档中的任何对象。但是,应用程序沙箱中的父级可以建立沙箱桥,以便与非应用程序沙箱中的内容通信。
下面的示例演示 AIR 中 iframe 标签的用法:
在无需映射到远程服务器上的实际域的情况下将 child.html 放置到远程沙箱中:
<iframe src="http://localhost/air/child.html"
documentRoot="app:/sandbox/"
sandboxRoot="http://localhost/air/"/>
在仅允许对 www.example.com 执行 XMLHttpRequest 的情况下将 child.html 放置到远程沙箱中:
<iframe src="http://www.example.com/air/child.html"
documentRoot="app:/sandbox/"
sandboxRoot="http://www.example.com/air/"/>
在允许对任何远程域执行 XMLHttpRequest 的情况下将 child.html 放置到远程沙箱中:
<iframe src="http://www.example.com/air/child.html"
documentRoot="app:/sandbox/"
sandboxRoot="http://www.example.com/air/"
allowCrossDomainXHR="allowCrossDomainXHR"/>
将 child.html 放置到只能与本地文件系统内容交互的沙箱中:
<iframe src="file:///templates/child.html"
documentRoot="app:/sandbox/"
sandboxRoot="app-storage:/templates/"/>
使用 dominitialize 事件建立沙箱桥,并将 child.html 放置到远程沙箱中:
<html>
<head>
<script>
var bridgeInterface = {};
bridgeInterface.testProperty = "Bridge engaged";
function engageBridge(){
document.getElementById("sandbox").parentSandboxBridge = bridgeInterface;
}
</script>
</head>
<body>
<iframe id="sandbox"
src="http://www.example.com/air/child.html"
documentRoot="app:/"
sandboxRoot="http://www.example.com/air/"
ondominitialize="engageBridge()"/>
</body>
</html>
以下 child.html 文档说明子级内容如何访问父级沙箱桥:
<html>
<head>
<script>
document.write(window.parentSandboxBridge.testProperty);
</script>
</head>
<body></body>
</html>
有关详细信息,请参阅跨脚本访问不同安全沙箱中的内容和 Adobe AIR 中的 HTML 安全性。