MediaWiki:Gadget-extlinks.js
Jump to navigation
Jump to 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. Adapted from wikibooks page with same name.
$(document).ready( function($) {
var server = mw.config.get( 'wgServer' );
mw.util.$content.find('a').each( function() {
var $link = $(this);
if ( !$link.hasClass( 'external' ) && !$link.hasClass( 'extiw' ) ) {
return;
}
// check hostname first where available as second test may not catch all links that it should
if ( this.hostname === location.hostname || $link.attr('href').substr(0, server.length) === server ) {
return;
}
$link.attr( 'target', '_blank' );
});
});