问题描述
||
我已经开发了Adobe AIR应用程序,可以在HTML控件中打开网站面板。我意识到HTML控件会打开在同一窗口中打开的链接,但是它不会打开在新窗口中打开的链接,即具有属性(target = \“ _ blank)的链接,如下所示:
<a href\"\" target=\"_blank\"> Opens in new window </a>
我已经在网上搜索过,尽管这里有一个带有“ _blank”链接的AIR HTML解决方案,但是它在浏览器中打开了链接,而且链接太旧了(2008年9月)。那么,有人知道打开链接的另一种简单方法吗?
解决方法
我重写了您发现更改锚定目标的示例,现在在同一窗口中打开了链接。但是这种方法有局限性-只有静态链接是固定的,任何试图在新窗口中打开链接的JS方法都会失败。
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<mx:WindowedApplication
xmlns:mx=\"http://www.adobe.com/2006/mxml\" layout=\"absolute\"
initialize=\"init()\">
<mx:Script>
<![CDATA[
private function init():void
{
html.htmlText =
\"<html><body>\" +
\"<a href=\'http://adobe.com\' target=\'_blank\'>Adobe (blank)</a><br/>\" +
\"<a href=\'http://ixbt.com\' target=\'_self\'>iXBT (self)</a>\" +
\"</body></html>\";
html.addEventListener(Event.COMPLETE,onHTMLComplete);
}
private function onHTMLComplete(event:Event):void
{
var document:Object = html.domWindow.document;
for each (var anchor:Object in document.getElementsByTagName(\"a\"))
{
if (anchor.hasOwnProperty(\"target\"))
{
if (anchor.target == \"_blank\")
{
anchor.target = \"_self\";
}
}
}
}
]]>
</mx:Script>
<mx:HTML id=\"html\" width=\"100%\" height=\"100%\"/>
</mx:WindowedApplication>