לדלג לתוכן

מדיה ויקי:Gadget-ExternalLinkNewTab.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
(T143849) Use rel="noopener noreferrer" on external links with _blank target to prevent window.opener phishing (See https://dev.to/phishing) - per m:User:BWolff (WMF)
 
מ גרסה אחת של הדף wikipedia:he:מדיה_ויקי:Gadget-ExternalLinkNewTab.js יובאה
 
(אין הבדלים)

גרסה אחרונה מ־19:14, 5 בדצמבר 2022

/***
SOURCE: mediawiki.org/wiki/Snippets/Open_external_links_in_new_window
***/
mw.hook( 'wikipage.content' ).add( function( $content ) {
	$content.find( 'a.external, a[rel="mw:ExtLink"]' ).each( function () {
		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
			}
		}
	} );
} );