[英]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.