미디어위키 : Gadget-exlinks.js

위키百科, 우리 모두의 百科事典.

參考: 設定을 貯藏한 後에 바뀐 點을 確認하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬 , 파이어폭스 , 마이크로소프트 엣지 , 사파리 : ? Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 仔細한 情報를 보려면 위키百科:캐시 無視하기 項目을 參考하십시오.

// **********************************************************************

// **                 ***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

			}

		}

	});

});