Search code examples
apache-flexflashair

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?


Solution

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