在新窗口打开wiki的外部链接

Find this function in ‘YourWikifolder\includes\Skin.php’ and change to:

function bottomScripts() {
global $wgJsMimeType;
return “\n\t\t<script type=\”$wgJsMimeType\”>if (window.runOnloadHook) runOnloadHook();</script>\n”
.” <script type=’text/javascript’ src=’../javascript_form/getXterlinks.js’></script>\n”
.” <script type=’text/javascript’>getXterlinks()</script>\n”;
}

Then create a folder and a file in ‘YourWikifolder/javascript_form/getXterlinks.js’, and copy and paste this into the file then save it (don’t forget to set the right value for “YourdomainWithoutHttp”):

function getXterlinks()
// By Thong Nguyen [email protected]
// This code just VIRTUALLY add a target=”_Blank” to any external link in the wiki document!
// NOTE: YOU DON”T Need to modify any of your text document!
{
var Xterlinks = document.getElementsByTagName(‘A’);
for (var i=0;i<Xterlinks.length;i++)
{
var eachLink = Xterlinks[i];
var regexp_isYourdomain=”YourdomainWithoutHttp”; //for example “meta.wikimedia”
var regexp_ishttp=/(http(.)*:\/\/)/;
//Check if the link is valid and is external link
if( (eachLink.href != null) && (eachLink.href.match(regexp_isYourdomain) == null) && eachLink.href.match(regexp_ishttp)!=null )
{
eachLink.target =”_blank”;//make the target for this external link
}
}
}

MediaWiki versions Tested in 1.9.3

Or you can follow ANOTHER METHOD below.

This page describes how to change the MediaWiki code so that external links open in a new window.

Keep in mind that some consider it rude to force new windows on your users. Additionally, if you are using Google AdSense (or similar services) on your wiki, these links should open within the same browser (“_self) according to the policies of the Ad Service.

发表评论

你必须 登录 才能发表评论.