在不使用jQuery的情况下,使用JavaScript在新标签页中打开所有外部链接(与当前域不匹配的URL)的最佳方式是什么?在没有jQuery的情况下在新标签页中打开外部链接
这里是jQuery的我用电流:
// Open external links in new tab
$('a[href^=http]').click(function() {
var a = new RegExp('/' + window.location.host + '/');
if (!a.test(this.href)) {
window.open(this.href);
return false;
}
});
完美,谢谢! – AlecRust