Author Topic: Extending links  (Read 1326 times)

MPete

  • Full Member
  • ***
  • Posts: 62
Extending links
« on: November 20, 2009, 03:55:30 am »
Is there a way to convert links into JavaScript commands or listen for clicks and attach them to JavaScript functions?

example: I want to change http://www.example.com into javascript:trackLink('http://www.example.com','link',3,8) instead of having to put this custom link format in every time...

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Extending links
« Reply #1 on: November 23, 2009, 09:27:03 pm »
Well, if you don't need the googleanalytics plugin, then yes, easily done using a small plugin. It would do pretty much the same thing the googleanalytics plugin does now (which is why that wouldn't be compatible), that being the overriding of the default link handling functions.

The ga plugin does this:
Code: (actionscript3)
  1. // in "initialize()"
  2. links.registerProtocol("http://", trackingHandler);
  3. // trackingHandler is the function handling the links, signature is
  4. function trackingHandler(url:String, source:IElement = null,
  5.            target:String = null):void;

The plugin to do that would do the following:
Code: (actionscript3)
  1. // in "initialize()"
  2. links.registerProtocol("http://", convertingHandler);
  3. // convertingHandler is the function handling the links, would look something like this
  4. function convertingHandler(url:String, source:IElement = null,
  5.            target:String = null):void
  6. {
  7.    navigateToURL(new URLRequest("javascript:trackLink(\"" + url + "\", \"link\", 3, 8)"), target);
  8.    // *OR*, of the javascript plugin is loaded (cleaner way, using ExternalInterface
  9.    // in the js plugin which registers a handler for javascript: links)
  10.    (pluginManager.getPlugin("links") as ILinks).
  11.            processLink("javascript:trackLink(\"" + url + "\", \"link\", 3, 8)");
  12. }

At least in principle. ;)
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.