AIR HTML with “_blank” Links Part II - Using HTMLHost
Thursday 4 September 2008 @ 11:37 am

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.open, 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!

- Posted in AIR by Sönke  




One Response to 'AIR HTML with “_blank” Links Part II - Using HTMLHost'

  1. Erik Hansen - September 10th, 2008 at 9:03 am

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


Leave a Reply