[Mediawiki-l] External Link Opening in New Tab or Window

Charlie Markwick charlie-markwick at southcot.com
Mon Jan 24 16:25:17 UTC 2011


From: Charlie Markwick 
Sent: 24 January 2011 15:04
To: 'MediaWiki announcements and site admin list'
Subject: RE: [Mediawiki-l] External Link Opening in New Tab or Window

Just put the following JavaScript code in your wiki's
MediaWiki:Common.js page:

// Anything in this function wrapper will be executed when the page is
ready for action
( function( $ ) {
$( document ).ready( function() {
 
// Open external links in the sidebar in a new window
$( '#mw-panel, #panel' ) // #panel is for pre-1.17 compatibility
        .find( 'li a' )
        .filter( '[href^=http://], [href^=https://]' )
        .attr( 'target' , '_blank' );
} );
} )( jQuery );

-------------------------------

I've added it to MediaWiki:Common.js but it changes nothing. I have
tried clearing the cache and also accessing the URL using another
browser that hasn't accessed the wiki before. No difference.

-------------------------------

Just noticed that there a a rogue line break in my e-mail below. My
common.js reads:-

/* Any JavaScript here will be loaded for all users on every page load.
*/

// Anything in this function wrapper will be executed when the page is
ready for action 
( function( $ ) { 
$( document ).ready( function() {
 
// Open external links in the sidebar in a new window

$( '#mw-panel, #panel' ) // #panel is for pre-1.17 compatibility
        .find( 'li a' )
        .filter( '[href^=http://], [href^=https://]' )
        .attr( 'target' , '_blank' );
} );
} )( jQuery );


Charlie



More information about the MediaWiki-l mailing list