Revision [20571]

This is an old revision of OpenExternalInNewWindow made by ErikAnderson on 2009-04-24 09:45:39.

 


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.

Step 1 for Wikka version =1.1.6.6


Locate this line in the source:

           $result = '<a class="'.$class.'" href="'.$url.'">'.$text.'</a>';


In Wikka version 1.1.6.6, you can find the code in libs/Wakka.class.php at line 1050.

Replace it with... (rest of instructions to follow shortly -EA)

Step 1 for Wikka versions <1.1.6.6


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;
                }


Step 2


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:


CategoryUserContributions
There are 4 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki