Jump to content

Snippets/Open specific links in new window

From mediawiki.org
How to use Snippets
List of Snippets
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>

Code

[edit]
/**
 * @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 also

[edit]