MediaWiki:Gadget-exlinks.js

2019年7月28日 (日) 11:33時点におけるOchaochaocha3 (トーク | 投稿記録)による版 (「外部リンクを新しいウィンドウ・タブで開く」をバージョン5に更新する)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: メニュー → 設定 (Mac では Opera → 環境設定) に移動し、プライバシーとセキュリティ → 閲覧データを消去 → キャッシュされた画像およびファイル からキャッシュをクリアしてください。
// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
/**
 * @source mediawiki.org/wiki/Snippets/Open_external_links_in_new_window
 * @version 5
 */
mw.hook('wikipage.content').add(function($content) {
	// Second selector is for external links in Parsoid HTML+RDFa output (bug 65243).
	$content.find('a.external, a[rel="mw:ExtLink"]').each(function () {
		// Can't use wgServer because it can be protocol relative
		// Use this.href property instead of this.getAttribute('href')  because the property
		// is converted to a full URL (including protocol)
		if (this.href.indexOf(location.protocol + '//' + location.hostname) !== 0) {
			this.target = '_blank';
			if ( this.rel.indexOf( 'noopener' ) < 0 ) {
				this.rel += ' noopener'; // the leading space matters, rel attributes have space-separated tokens
			}
			if ( this.rel.indexOf( 'noreferrer' ) < 0 ) {
				this.rel += ' noreferrer'; // the leading space matters, rel attributes have space-separated tokens
			}
		}
	});
});