在不使用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