javascript 使用“parent.location”在提交按钮上打开新窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4967623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open New Window on Submit Button with "parent.location"
提问by Erik Chan
I'm having a hard time getting a submit button to open a link in a new window.
我很难获得一个提交按钮来在新窗口中打开链接。
The button code:
按钮代码:
<input type="button" name="buy" value="Buy" onClick="parent.location='myurl'" />
I tried to add a target="_blank" to the form, but that didn't help.
我试图在表单中添加一个 target="_blank" ,但这没有帮助。
Is it possible to open a new window using this "parent.location" method or any equivalent.
是否可以使用此“parent.location”方法或任何等效方法打开一个新窗口。
I'm afraid my shopping cart script won't work any longer if I change the code too much.
如果代码更改过多,恐怕我的购物车脚本将不再起作用。
Best regards,
最好的祝福,
Erik Chan
陈奕迅
回答by David Morin
<form action="whatever" method="post" target="foo" onSubmit="window.open('', 'foo', 'width=1040,height=900,status=yes,resizable=yes,scrollbars=yes')">
This should work for your needs. I have used this time and time again
这应该可以满足您的需求。我一次又一次地使用这个
回答by zozo
Try window.open() method.
尝试 window.open() 方法。
<input type="button" name="buy" value="Buy" onclick="window.open('myurl')">
回答by Manish Trivedi
<input type="button" name="buy" value="Buy" onClick='window.open("http://www.abcd.com/")' />
see it for open function param http://www.w3schools.com/jsref/met_win_open.asp

