JD Isaacks
JD Isaacks

Reputation: 57974

Does window.open not work inside an AIR html component?

I have a component in AIR like so:

<mx:HTML
        id="html"
        width="100%" 
        height="100%" 
        location="https://example.com" 
        locationChange="dispatchLocationChange(event)"
    />

The page it loads contains this:

<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>

The 2 alerts both work. however nothing happens when you click the new window link.

all 3 links works when in a real browser so I know its ok.

Is there just no support for window.open in the AIR HTML component? or is this a bug?

Is there a work around?

Upvotes: 2

Views: 853

Answers (2)

Juan Delgado
Juan Delgado

Reputation: 2030

Try: navigateInSystemBrowser.

Example:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
      <![CDATA[
            private function init():void
            {
                  html.htmlLoader.navigateInSystemBrowser = true;
            }
      ]]>
</mx:Script>
      <mx:HTML location="test.html" id="html" creationComplete="init()"/>
</mx:WindowedApplication>

Upvotes: 1

JD Isaacks
JD Isaacks

Reputation: 57974

I found out you need to extend the class HTMLHost and override the createWindow method like this:

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;
}

Then set this subclass as the htmlHost property for the HTML component.

This does get it to work. But there is some strange behavior in the new popup window. Seems kinda buggy.

Upvotes: 2

Related Questions