[TYPO3] Adding onClick event to all internal links

Zachary Davis, Cast Iron Coding LLC zach at castironcoding.com
Wed May 14 22:02:11 CEST 2008


Loek,

It's going to be tough to do this globally. As you say, making the 
change in parseFunc config will accomplish this for links that come from 
  regular page content. You could also change how the <link> tag gets 
rendered by modifying parseFunc (the link in your post may address that 
-- I didn't check). In theory, good extensions should be generating 
links using TypoScript or one of the core methods for generating links. 
Some extensions may have TypoScript configuration for the links, but it 
will most likely be time consuming to tweak each extension to render 
links the way you want them rendered.

One approach that might work (this is off the top of my head -- no 
promises) would be to use a userFunc on the page object. For example, 
this might work:

page = PAGE
page.stdWrap.postUserFunc = user_yourClass->yourMethod

I think that way you could get at the rendered content of the page in a 
PHP function. At that point you could pass it through a regular 
expression or even put it through an HTML parser and inject your onClick 
action. Probably not the best answer from a performance perspective, but 
then that all depends on site size / traffic.

Another option, of course, would be to accomplish this clientside using 
javascript. You could simply trigger an event after the dom is loaded to 
add click event listeners to each a tag. Depending on how many links you 
have on a page, this could be a better solution.

Hope this helps!

best,
Zach

-- 
-----------------------------
Zach Davis
Cast Iron Coding - Portland OR, USA
http://www.castironcoding.com
zach at castironcoding.com



Loek Hilgersom wrote:
> Hi,
> 
> Does anyone know how I can add an event like onClick="..." to all 
> internal links?
> 
> If I use  config.ATagParams  it will be appended to all links. Using 
> config.intTarget  only allows to set the target.
> 
> I also found this HowTo:
> http://wiki.typo3.org/index.php/External_links
> but that seems to affect only links from the RTE or extensions using 
> parsefunc.
> 
> Thanks,
> Loek


More information about the TYPO3-english mailing list