Copy link to clipboard
Copied
I have an Air app, which loads my website through htmlLoader, and allows users to log in and interact with it through the app. My problem is I want some links to open outside the app (ie, in the default browser) but I havn't a clue on how to do this. I've tried navigateInSystemBrowser in the htmlLoader class, but for some reason, this opens the initial page in the default browser, and leaves my app empty. Any ideas?
then you can use the dom references for your links to detect when a link is clicked and you can execute code to reload the html page (so the html-linked page doesn't load) and you can use navigateToURL. for example:
var htmlLoader:HTMLLoader = new HTMLLoader();
htmlLoader.width = 300;
htmlLoader.height = 300;
addChild(htmlLoader);
htmlLoader.addEventListener(Event.COMPLETE, completeHandler);
htmlLoader.load(new URLRequest("http://www.kglad.com/Files/test/menu.html"));
function completeHandler(event:E
...Copy link to clipboard
Copied
use navigateToURL.
Copy link to clipboard
Copied
How do I use it. My link is on my website, which is then loaded into the app through htmlLoader. (might not've made that clear, sorry)
Copy link to clipboard
Copied
if the links on your website are already coded to load link targets, you shouldn't need any coding in your swf to enable that functionality.
you might have a security sandbox issue however that would require a permissions file on your website.
Copy link to clipboard
Copied
Sorry, I don't understand, the links open within the app already, what I want them to do is outside the app. (like in a browser) I've tried to use window.open in javascript, or "_blank" in html, and neither have worked.
Copy link to clipboard
Copied
you're using htmlLoader to load an html page, correct?
that page contains html links, correct?
those html links are encoded with anchor tags, correct?
Copy link to clipboard
Copied
yes
Copy link to clipboard
Copied
then you can use the dom references for your links to detect when a link is clicked and you can execute code to reload the html page (so the html-linked page doesn't load) and you can use navigateToURL. for example:
var htmlLoader:HTMLLoader = new HTMLLoader();
htmlLoader.width = 300;
htmlLoader.height = 300;
addChild(htmlLoader);
htmlLoader.addEventListener(Event.COMPLETE, completeHandler);
htmlLoader.load(new URLRequest("http://www.kglad.com/Files/test/menu.html"));
function completeHandler(event:Event):void {
htmlLoader.window.document.getElementsByTagName("a")[0].onclick = clickHandler;
}
var t:Timer=new Timer(1,1);
t.addEventListener(TimerEvent.TIMER,reloadF);
function clickHandler(e:Object):void{
t.start();
htmlLoader.removeEventListener(Event.COMPLETE, completeHandler);
navigateToURL(new URLRequest(htmlLoader.window.document.getElementsByTagName("a")[0].href));
}
function reloadF(e:TimerEvent):void{
htmlLoader.load(new URLRequest("http://www.kglad.com/Files/test/menu.html"));
}
Copy link to clipboard
Copied
Thanks a lot! That was exactly what I was looking for! Just one more thing though, how do I make the link only open in the browser, and not in the app aswell. (So when I click it, the url opens in the browser, but the app stays on the page it was originally on)
Copy link to clipboard
Copied
that's what reloadF does.
Copy link to clipboard
Copied
Oh, sorry, I just had two different urls that was the problem. Thanks so much! It's working fine!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now