ExpressionEngine Plug-in: Link Target
Jul 09. 08Not sure how useful this ExpressionEngine Plug-in will be to others out there but we’re using it here at Nine Four on the Wired In website to link from an IFrame back to the parent window. This is something you would usually achieve with:
<a href="http://www.nathanpitman.com" target="_top">My Link Text</a>
…but that’s not valid XHTML so instead we need to do:
<a href="http://www.nathanpitman.com" onClick="top.location=this.href; return false">My Link Text</a>
The ‘Link Target’ plug-in just helps to keep your template code clean by writing all the JavaScript for you. Typical usage of the plug-in is as follows:
{exp:np_linktarget url="http://www.nathanpitman.com" target='top'}My Link Text{/exp:np_linktarget}
By default you have to specify a ‘url’ and ‘target’ parameter and the plug-in also optionally accepts a link ‘title’ and ‘class’. Possible ‘type’ values are ‘top’ and ‘blank’. Each mimic the link target attributes ‘_top’ and ‘_blank’ respectively.
Download: pi.np_linktarget.php.zip
Obviously let me know in the comments if you have any thoughts on how this can be improved. Enjoy!