MediaWiki:Common.js: Difference between revisions
Dragon 12dk (talk | contribs) No edit summary |
Dragon 12dk (talk | contribs) No edit summary |
||
| Line 11: | Line 11: | ||
} | } | ||
// Force links to open in new tab in | // Force links to open in new tab when embedded in an iframe | ||
( function () { | |||
if ( window === window.top ) return; | |||
function retargetLinks() { | |||
if (!href || href.startsWith('#')) return; | document.querySelectorAll( 'a[href]' ).forEach( function ( link ) { | ||
var href = link.getAttribute( 'href' ); | |||
if ( !href || href.startsWith( '#' ) ) return; | |||
link.setAttribute( 'target', '_blank' ); | |||
link.setAttribute( 'rel', 'noopener noreferrer' ); | |||
} ); | |||
} | |||
window.addEventListener( 'load', retargetLinks ); | |||
if ( typeof mw !== 'undefined' ) { | |||
mw.hook( 'wikipage.content' ).add( retargetLinks ); | |||
} | |||
} )(); | |||
( function () { | ( function () { | ||