MediaWiki:Gadget-ExternalLinkNewWin.js:修订间差异
删除的内容 添加的内容
创建页面,内容为“→此小工具设定外部链接在被点按后于新页签或视窗开启(视乎浏览器而定)。: $(function(){ $("a.external").filter(function(idx){ var h=(""+$(this).attr("href")).split("\/"); if(h.length<3) return false; if(h[2]==location.host) return false; return true; }).attr("target", "_blank"); });” |
小无编辑摘要 |
||
第1行: | 第1行: | ||
// ********************************************************************** |
|||
⚫ | |||
// ** ***WARNING GLOBAL GADGET FILE*** ** |
|||
此小工具设定外部链接在被点按后于新页签或视窗开启(视乎浏览器而定)。 |
|||
// ** changes to this file affect many users. ** |
|||
⚫ | |||
// ** please discuss on the talk page before editing ** |
|||
// ** ** |
|||
$(function(){ |
|||
// ********************************************************************** |
|||
$("a.external").filter(function(idx){ |
|||
⚫ | |||
var h=(""+$(this).attr("href")).split("\/"); |
|||
* @source mediawiki.org/wiki/Snippets/Open_external_links_in_new_window |
|||
if(h.length<3) return false; |
|||
* @version 5 |
|||
if(h[2]==location.host) return false; |
|||
⚫ | |||
return true; |
|||
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) { |
|||
⚫ | |||
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 |
|||
} |
|||
} |
|||
}); |
|||
}); |
}); |
2022年12月10日 (六) 11:37的最新版本
// **********************************************************************
// ** ***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
}
}
});
});