Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


How can I configure external links to always open in a new window?


Add the following to config.php:

    $UrlLinkFmt = 
      "<a class='urllink' target='_blank' href='\$LinkUrl'>\$LinkText</a>";


The $UrlLinkFmt variable specifies the HTML to be output when an external link is generated by PmWiki. The above line simply adds target='_blank' to the HTML so that each external link is opened in a new window.


  • Pm - 10-Jul-2004

(more semantic) Alternative

You could use

    $UrlLinkFmt = "<a class='urllink' rel='extern' href='\$Url'>\$LinkText</a>";

in config.php.

Then put

 function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "extern")
     anchor.target = "_blank";
 window.onload = externalLinks;

into a file - say - 'extern.js'.


   <script type='text/javascript' src='PATH/extern.js'></script>

to your template will call the script on pageload.

For more on this - nicer - solution have a look at [(approve links) edit diff].


pmwiki-2.3.34 -- Last modified by {{gunter}}?

from IP: ip should be disabled by default for security reasons