Window.open + href替换并弹出到新窗口但不使用target _blank

时间:2011-05-13 00:22:46

标签: javascript window href

我遇到了一些问题,我想让Test 1和Test 2链接在新窗口中弹出, target = _blank进入一个新窗口,这样弹出窗口就不会出现' t作为firefox等中的选项卡打开.javascript中的"href"将填充测试1和测试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>

2 个答案:

答案 0 :(得分:3)

您的代码似乎没问题,只是它缺少“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')";

答案 1 :(得分:0)

我不确定您对该代码的期望是什么,但以下内容对您有用:

<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>
相关问题