Adobe AIR HTML组件,加载本地应用程序HTML,但允许远程(http)脚本和内容

时间:2013-04-28 22:43:51

标签: html flex air sandbox

我希望在AIR应用程序中将包含的html文件加载到Flex HTML组件中,并且该html文件将包含对远程内容的引用。 AIR中的默认设置是不允许这样做 - 从应用程序本地加载的内容然后禁用远程内容。

我在他们的文档中看到,看起来可能会改变这一点,但我找不到(经过全面挖掘)如何做到这一点。

从他们的文件:

  

页面中内容的来源决定了它所在的沙箱   托运。仅从应用程序目录加载内容(   应用程序引用的安装目录:URL方案)放在   应用程序沙箱。放置从文件系统加载的内容   在local-with-filesystem或本地信任的沙箱中,哪个   允许访问和交互本地文件系统上的内容,   但不是远程内容。从网络加载的内容放在一个   远程沙箱对应于其原始域。

     

应用程序沙箱中的HTML页面无法使用脚本标记   从应用程序目录外部加载JavaScript文件。   为了使应用程序中的页面从外部加载脚本   在应用程序目录中,页面必须映射到a   非应用沙箱。

那很好但我怎么做到这一点?

想要加载本地文件(app:/google-maps/capture.html),但允许使用远程内容()以便Google地图正常运行。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

回答了我自己的问题。

http://livedocs.adobe.com/flex/3/html/help.html?content=ProgrammingHTMLAndJavaScript_11.html

“将应用程序内容加载到非应用程序沙箱”部分回答了它。

解决方案:

我需要两个html文件,加载到flex中的文件只包含一个iframe,它试图加载我想要显示的实际文件。

capture2.html(加载到HTML组件中)

    <iframe width="100%" height="100%"
    src="capture.html"
    sandboxRoot="http://google.com/"
    documentRoot="app:/google-map-capture/">
    </iframe>

然后在我实际想要显示的文件中(capture.html):

<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
var map;
function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

完美无缺。