Open main menu

Snippets/Open specific links in new window

How to use Snippets
List of Snippets
Crystal Clear action run.png
Open specific links in new window
Language(s): JavaScript
Compatible with: MediaWiki 1.22+ (Vector; Monobook; Modern)

This snippet allows any given link that's directly wrapped inside an element with class="newwin" to open on a new window when clicked.

For example, this syntax would make the link to open on a new window when clicked:

<span class="newwin">[[MediaWiki]]</span>

CodeEdit

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Open_specific_links_in_new_window
 * @version 2018-09-15
 */
$( function () {
	$( '#mw-content-text' ).on( 'click', '.newwin > a', function () {
		var otherWindow = window.open();
		otherWindow.opener = null;
		otherWindow.location = this;
		return false;
	} );
} );

See alsoEdit