Snippets/Open specific links in new window
< Snippets
(Redirected from Snippets/Open specific external links in new window)This snippet allows any given link that's directly wrapped inside an element with class="newwin" to open on a new window when clicked.
Open specific links in new window | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.22+ (Vector; Monobook; Modern) |
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;
} );
} );