How to download linked HTML files within AIR application?

Asked

Viewed 133 times

0

I created an application with Adobe AIR and played within it the HTML component that will open my desired page. The problem I’m having is that within this HTML page there are some functions to download files, but these do not work because they are inside the AIR application.

Any idea what I can do to be able to download these files from the HTML page inside the AIR application?

With the code below the page until you open the download link, but it is empty, open a popup but the file is not downloaded and I can’t even view this.

htmlContent.location = "minha url";
var htmlhost:HTMLHost = new HTMLHost(true);         
htmlContent.htmlLoader.htmlHost = htmlhost; 

1 answer

2


I found the solution to my problem in this tutorial, I hope it suits someone.

The solution is to create, by code, an Handler onclick for all links on the page after it has loaded, and use navigateToURL inside that Handler to open the link in the browser.

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HTML id="htmlComp" width="100%" height="100%" location="http://www.rediff.com" complete="addEventListenersToLinks(event)"  />

 <mx:Script>
  <![CDATA[

   private function addEventListenersToLinks(e:Event):void
   {
    var dom:Object = e.currentTarget.domWindow.document;
    var links:Object = dom.getElementsByTagName("a");

    for(var i:Number = 0; i < links.length; i++)
    {
     if(links[i].target.toLowerCase() == "_blank" || links[i].target.toLowerCase() == "_new")
      links[i].onclick = linkClickHandler;
    }
   }

   private function linkClickHandler(o:Object):void
   {
    navigateToURL(new URLRequest(o.currentTarget.href),"blank");
   }
  ]]>
 </mx:Script>
</mx:WindowedApplication>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.