Skip to content

Instantly share code, notes, and snippets.

@FrancisVarga
Created November 26, 2009 00:43
Show Gist options
  • Save FrancisVarga/243135 to your computer and use it in GitHub Desktop.
Save FrancisVarga/243135 to your computer and use it in GitHub Desktop.
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//<a href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Creative Commons License<a\>
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//You are free:
//
//to Share — to copy, distribute and transmit the work
//to Remix — to adapt the work
//Under the following conditions:
//
//Attribution — You must attribute the work in the manner specified by the author or licensor
//(but not in any way that suggests that they endorse you or your use of the work).
//
//Noncommercial — You may not use this work for commercial purposes.
//
//Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
//
//With the understanding that:
//
//Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
//Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
//Other Rights — In no way are any of the following rights affected by the license:
//
//Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The author's moral rights;
//
//Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
//Notice — For any reuse or distribution, you must make clear to others the license terms of this work.
//The best way to do this is with a link to this web page.
//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
package cc.varga.utils
{
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class HTMLLinkHelper
{
public function HTMLLinkHelper()
{
}
public static function handleArchors(htmlLoader : HTMLLoader):void{
var linkTags:Object = htmlLoader.window.document.getElementsByTagName("a");
for(var i:uint=0; i < linkTags.length; i++) {
var aTag:Object = linkTags[i];
// Check if anchor has target and if it is _blank so it should be handled seperatly
var targetAttr:Object = aTag.attributes.getNamedItem("target");
if(targetAttr != null && targetAttr.nodeValue == "_blank")
{
var urlAttr:Object = aTag.attributes.getNamedItem("href");
aTag.onmouseup = function(o:Object):void{
//Cancels an event's default behavior if that behavior can be canceled.
o.preventDefault();
navigateToURL(new URLRequest(o.srcElement), "_blank");
};
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment