我在 AIR 中有一个组件,如下所示:
<mx:HTML
id="html"
width="100%"
height="100%"
location="https://example.com"
locationChange="dispatchLocationChange(event)"
/>
它加载的页面包含以下内容:
<a onclick="alert('onclick')">Alert</a>
<a href="javascript:alert('js')">Alert</a>
<a onclick="window.open('http://www.google.com','_blank')">new window</a>
这两个警报都有效。但是,当您单击新窗口链接时,什么也没有发生。
所有 3 个链接在真实浏览器中都有效,所以我知道它没问题。
AIR HTML 组件中是否不支持 window.open?或者这是一个错误?
有解决办法吗?
最佳答案
我发现您需要扩展 HTMLHost
类并重写 createWindow
方法,如下所示:
override public function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
{
var window:Window = new Window();
window.open();
window.visible = true;
window.height = windowCreateOptions.height;
window.width = windowCreateOptions.width;
var htmlLoader:FlexHTMLLoader = new FlexHTMLLoader();
htmlLoader.width = window.width;
htmlLoader.height = window.height;
htmlLoader.htmlHost = new MyHTMLHost();
window.stage.addChild(htmlLoader);
return htmlLoader;
}
然后将此子类设置为 HTML
组件的 htmlHost 属性。
这确实可以让它工作。但新的弹出窗口中有一些奇怪的行为。看起来有点问题。
关于apache-flex - window.open 在 AIR html 组件中不起作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3047722/