![](/img/trans.png)
[英]window.open with target '_blank' opens a new browser window
[英]Window.open + href replace and pop into new window but not using target _blank
我被卡在某些地方,希望“测试1”和“测试2”链接在新窗口中弹出, 而不是 target = _blank进入新窗口,因此弹出窗口不会在firefox中作为选项卡打开,等等。 javascript中的"href"
是填充Test 1和Test 2链接中的href #
。 我在做什么错,所以我也可以将弹出窗口打开到新窗口,但不能作为目标_blank?
<p><a id="test1" href="#">Test 1</a></p>
<p><a id="test2" href="#">Test 2</a></p>
<script>
if(chatlink_flag == 'true')
{
document.getElementById('test1')window.open.href('http://www.example.com/chat1/open.htm','window1','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
document.getElementById('test2')window.open.href('http://www.example.com/chat2/open.htm','window2','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}else{
document.getElementById('test1')window.open.href('http://www.example.com/chat1/closed.htm','window1','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
document.getElementById('test2')window.open.href('http://www.example.com/chat2/closed.htm','window2','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
</script>
您的代码看起来还可以,只是缺少“ javascript:”部分。
因此,您可以尝试执行window.open这样的行:
document.getElementById('test1').href = "javascript:window.open('http://www.yourpage.com/', 'window1', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no')";
我不确定您希望该代码执行什么操作,但是以下方法应该适合您:
<p><a id="test1" href="#" onclick="open_window(1);">Test 1</a></p>
<p><a id="test2" href="#" onclick="open_window(2);">Test 2</a></p>
<script type="text/javascript">
function open_window(id) {
if (chatlink_flag) {
window.open('http://www.example.com/chat' + id + '/open.htm','window' + id,'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
else {
window.open('http://www.example.com/chat' + id + '/closed.htm','window' + id,'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.