[TYPO3] Adding onClick event to all internal links

Loek Hilgersom hilgersom at xs4all.nl
Thu May 15 10:57:44 CEST 2008


Hi Zach,

We've been considering Javascript for this purpose but we already have quite a 
heavy set of client-side scripts. I'll check if the postUserFunc is an option, 
otherwise I may opt for adding the event to all links and just let javascript 
check whether the link is internal or not.

Thanks for your answer!

Loek




Zachary Davis, Cast Iron Coding LLC wrote:
> 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
> 


More information about the TYPO3-english mailing list