Javascript Window.open+;href replace并弹出新窗口,但不使用target\u blank

Javascript Window.open+;href replace并弹出新窗口,但不使用target\u blank,javascript,window,href,Javascript,Window,Href,我想让测试1和测试2的链接在新窗口中弹出,而不是在新窗口中弹出,这样弹出窗口就不会在firefox中作为选项卡打开,等等。javascript中的“href”用于填充测试1和测试2链接中的href。我这样做有什么不对,这样我也可以将弹出窗口打开到一个新窗口中,而不是作为一个目标空白 <p><a id="test1" href="#">Test 1</a></p> <p><a id="test2" href="#">Test

我想让测试1和测试2的链接在新窗口中弹出,而不是在新窗口中弹出,这样弹出窗口就不会在firefox中作为选项卡打开,等等。javascript中的
“href”
用于填充测试1和测试2链接中的href
。我这样做有什么不对,这样我也可以将弹出窗口打开到一个新窗口中,而不是作为一个目标空白

<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>

if(chatlink_标志=='true') { document.getElementById('test1')窗口。open.href('http://www.example.com/chat1/open.htm'、'window1'、'scrollbars=no、menubar=no、height=600、width=800、Resizeable=yes、toolbar=no、location=no、status=no'); document.getElementById('test2')窗口。open.href('http://www.example.com/chat2/open.htm'、'window2'、'scrollbars=no、menubar=no、height=600、width=800、Resizeable=yes、toolbar=no、location=no、status=no'); }否则{ document.getElementById('test1')窗口。open.href('http://www.example.com/chat1/closed.htm'、'window1'、'scrollbars=no、menubar=no、height=600、width=800、Resizeable=yes、toolbar=no、location=no、status=no'); document.getElementById('test2')窗口。open.href('http://www.example.com/chat2/closed.htm'、'window2'、'scrollbars=no、menubar=no、height=600、width=800、Resizeable=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>

功能打开窗口(id){ if(chatlink_标志){ 打开窗户http://www.example.com/chat“+id+”/open.htm“,“window”+id,“scrollbars=no,menubar=no,height=600,width=800,resizeable=yes,toolbar=no,location=no,status=no”); } 否则{ 打开窗户http://www.example.com/chat“+id+'/closed.htm',“window'+id,'scrollbars=no,menubar=no,height=600,width=800,resizeable=yes,toolbar=no,location=no,status=no'); } }
除了缺少“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')";

不幸的是,我无法将onclick添加到我的链接中。太单调了,我也不能。我们的链接在cms中管理,OnClick对我们不可用:(在这种情况下,只需将HREF更改为“javascript:open_window(1);”、“javascript:open_window(2);”等。或者,您可以使用jQuery将事件处理程序绑定到锚。谢谢您,这解决了我的问题。另外,通过添加“void”然后(open)阻止[object window]消息的返回值出现:document.getElementById)('test1').href=“javascript:void(打开(''window1','scrollbars=no,menubar=no,height=600,width=800,resizeable=yes,toolbar=no,location=no,status=no'))”;