Window.open + href 替换并弹出到新窗口中,但不使用目标_blank
Window.open + href replace and pop into new window but not using target _blank
我被困在我希望测试 1 和测试 2 链接在新窗口中弹出的东西上,而不是 target=_blank 进入新窗口,这样弹出窗口就不会在 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')";
我不确定您希望该代码做什么,但以下内容应该对您有用:
<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>
相关文章:
- 为什么HTML5拖放的目标是孩子?(可排序列表)
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- 对一个对象使用reduce可以返回一个没有't在数组中包含目标字母
- Href:当前DIV中的目标ID
- 当使用extern和目标JavaScript时,我如何强制Haxe编译器使用require语句
- 以ECMAScript 5及更高版本为目标时,八进制文字不可用
- 如何使用ember.js在操作中传递当前上下文中目标旁边的信息
- Javascript事件.锚的目标问题
- 任何一种简单的方法都可以将带有onload的元素作为目标
- 使用javascript将表单提交到iframe目标中
- 如何将GreaseMonkey中的XMLHttpRequest延迟到目标页面加载完成
- 通过JavaScript设置表单目标
- 当两个单独的单词被放在目标上时,使用Jquery获取一个值
- 如何从目标C中的stringByEvaluatingJavaScriptFromString:方法执行长javascri
- Firefox事件.目标问题
- AngularJs的ng-click$事件将子元素作为目标传递
- 从定位目标中的元素中清除类
- three.js EffectComposer's渲染目标
- 是否可以使用Jquery操作窗体的目标窗口
- 更改跳转到URL操作SSRS 2008 R2的链接目标属性(rc:LinkTarget)