MediaWiki:Gadget-extlinks.js

From Wikinews, the free news source you can write!
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

 // Make external links open in a new tab or window. Why someone would want this i have no idea. Copied from wikibooks page with same name.
 function external_links() {
   var links = document.getElementsByTagName('a');
 
   for (i = 0, length = links.length; i < length; i++)
   {
     if ((hasClass(links[i], "external") || hasClass(links[i], "extiw")) && links[i].href.indexOf(wgServer) != 0) {
       if (links[i].target)
         links[i].target = "_blank";
       else if (links[i].setAttribute)
         links[i].setAttribute("target", "_blank");
     }
   }
 }
 
addOnloadHook(external_links);
Personal tools
Namespaces
Variants
Actions
Navigation
Wikinews
Regions
Print/export
Toolbox