Adobe Air: Opening External Links in Another Browser

One of Sevenwire's recent projects has been building a complex desktop app in Adobe AIR using HTML and Javascript. It's been a pretty enjoyable experience for the most part. The environment is basically Webkit running inside of Flash, so getting to some of the system functionality (i.e. printing) through Flash can get a little complicated, but being able to write HTML/CSS for just Webkit has been a dream come true.

One interesting work around that took longer than it should to find was the ability to open a link in the user's default browser. Since you're already in Webkit when you're using the application, it tries to handle any links to external URLs itself by loading them in the same application window. For us, and I would assume a lot of people, we would prefer our AIR desktop app to function like other desktop apps and just open the link in the user's browser.

To do this, include the following javascript function in your app:

   1  // Open link in user's default browser window.
   2  function openExternalURL(href) {
   3    var request = new air.URLRequest(href);
   4    try {
   5      air.navigateToURL(request);
   6    } catch (e) {
   7      // handle error here
   8      air.Introspector.Console.log(e)
   9    }
  10  }
Original Source:

Then you can use jQuery to apply this behavior to all external links:

   1  // External Links
   2  $('a[href^=http]').live("click", function(event){
   3    event.preventDefault()
   4    openExternalURL(this.href)
   5  })

Or just plug the function into the onclick:

   1  <a href="#" onclick="openExternalURL(this.href); return false;">Link!</a>

Most agencies want to build it, bill it, and move on. Not us. We’re in it for the long haul. Nearly every client we’ve ever had is still our client and those applications are still running at full speed.


FlixCloud - On-demand Video Encoding Red Is White - Christian T-Shirts