我需要一个用于打开特定元素中所有链接的脚本,我需要它们在新选项卡中打开。我有以下代码打开所有链接,但在新窗口,而不是在选项卡中。
有可能这样做吗?
$('#result_list tbody a').each(function() {
var $this = $(this);
$this.attr('target', '_blank');
$this.get(0).click(function() {
window.open(this);
window.focus();
return false;
});
});
答案 0 :(得分:1)
我认为你不需要target =“_ blank”属性。默认情况下,window.open
在新窗口中打开。大多数现代浏览器都会将链接打开到新选项卡而不是新窗口。
$('#result_list tbody a').each(function() {
var $this = $(this);
$this.get(0).click(function() {
window.open(this);
window.focus();
return false;
});
});
您尝试过哪种浏览器?