javascript - Window.open + href 替换并弹出到新窗口但不使用目标_blank

标签 javascript window href

我卡在某个地方,我希望测试 1 和测试 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>

最佳答案

除了缺少“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')";

关于javascript - Window.open + href 替换并弹出到新窗口但不使用目标_blank,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5986007/

相关文章:

c# - 带 C# 的 SFML,启动麻烦

JavaScript 通过 href 获取元素?

javascript - JS : Issue getting values from drop-down menu to replace parts of HREF strings

javascript - 无法解析 JSON 字符串属性中存在的 XML

java - 当我将窗口设置为不透明时,字体看起来发生了变化

javascript - 将文件夹中的所有图像包含在数组中的最佳方法是什么?

JavaScript、浏览器、窗口关闭 - 发送 AJAX 请求或在窗口关闭时运行脚本

javascript - .attr ('href' )返回未定义

javascript - 如何绑定(bind)函数而不是创建新函数?

javascript - 如何在点击列表项时打开相应的标记信息窗口