[TYPO3] Adding onClick event to all internal links

Thorfinn dummy at email.nu
Fri May 23 12:47:23 CEST 2008


Usin Unobtrusive Javascript, you can do something like this:

http://phpfi.com/319029

--
Peter Klein


On Thu, 15 May 2008 10:57:44 +0200, Loek Hilgersom
<hilgersom at xs4all.nl> wrote:

>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