AIR HTML with “_blank” Links Part II – Using HTMLHost

I few days ago I blogged about how to open target=”_blank” anchor links in the system browser and leaving normal links in the HTML control of AIR. Since that I learned a bit more and people pointed me to the AIR docs. There you can find a great chapter about “Defining browser-like user interfaces for HTML content”.

So there is an easier method like mine which waited for the complete event of the HTML control and added custom event listeners for each anchor tag.

Like it is described in the docs you can extend the default HTMLHost class with for instance CustomHost. To handle links which should open a new window you simply override the createWindow method and implement it fitting to your needs

The simpliest approach might be using HTMLLoader.createRootWindow:

public override function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
	return HTMLLoader.createRootWindow();

To set the new CustomHost the HTML control can be defined like this:

<mx:HTML htmlHost="{new CustomHost()}" />

Besides that you can override a bunch of other methods which would trigger because of called JavaScript functions like, window.close, window.blur, etc.. If you use the HTML control of AIR be sure to read about “Scripting the HTML Container” with all its sub-chapters – great read!

5 comments to AIR HTML with “_blank” Links Part II – Using HTMLHost

  • I was looking for a way to do this. Thanks for posting!

  • Jeanelle Blackman

    Thanks for posting! I tried to use this in my code and kept getting an error “1020: Method marked override must override another method.” Do you have any idea what this means?

  • Have you subclassed HTMLHost?

  • Daniel

    Hi bro!
    Very nice.
    Do you know how i make to download works fine inside a AIR HTML Class?
    Best Regards,

  • Thanks, this blog helped me in narrowing down some issues with the latest release candidate, Why do they always seem to leave out vital documentation when they release a new version? It may be trivial to them but not to me. I’m sure i’m not alone either.