Open External Links In A New Window
This simple code modification will open
all external links in a new window or tab, depending on your browser's configuration. This modification is useful to prevent users from navigating away from the wiki when they click an external link. External links are defined as any link that leaves the Wiki (even if they are on the same server).
Note: This modification also requires XHTML Transitional. XHTML Strict is not supported, since the target attribute is not allowed. If you don't understand this and/or haven't modified the DOCTYPE in
actions/header.php, then you don't need to worry about this.
Locate this line in the source:
return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
In Wikka versions <1.1.6.2, you can find the code in
wikka.php, somewhere around line 662.
In Wikka versions >=1.1.6.2, you can find the code in
libs/Wakka.class.php, somewhere around line 882.
Replace it with this:
$external_link_new_window = $this->GetConfigValue("external_link_new_window");
if ($external_link_new_window = "0") {
return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
} else {
return $url ? "<a class=\"ext\" href=\"$url\" target=\"_new\">$text</a>$external_link_tail" : $text;
}
Then add the following element to the
wikka.config.php wakkaConfig array:
'external_link_new_window' => '1'
'0' (zero) turns off opening external links in a new window. Any non-zero value turns on opening external links in a new window.
That's all there is to it. --
JasonHuebel
TODO:
- Need to add info on modifying actions/rss.php, which should always be considered external
CategoryUserContributions