admin 管理员组文章数量: 1086019
So I know this is a dumb question, but I haven't been able to find a precise answer to my specific issue. I have tried changing the submit button to a regular button and adding an onClick
event... no dice. I am trying to submit a form to a new, custom-sized window (so not a new tab in Chrome, etc). I have gotten it so it opens the submitted form data on the new page in a new window, but the custom sized-window is also opened as a blank page.
<form action="Upload.cfm" target="_blank" enctype="multipart/form-data" method="post" onSubmit="window.open('', 'mywindow3','left=0,width=900,height=600,z-index=20, resizable=yes, scrollbars=yes');">
If i remove the onSubmit javascript, it just opens a new tab (again, not what I want). If i remove the target="_blank"
, it just opens a new tab as well.
What I really want to do is have the window.open
dimensions in my onSubmit event apply to the submitted form page, not an extraneous blank page.
So I know this is a dumb question, but I haven't been able to find a precise answer to my specific issue. I have tried changing the submit button to a regular button and adding an onClick
event... no dice. I am trying to submit a form to a new, custom-sized window (so not a new tab in Chrome, etc). I have gotten it so it opens the submitted form data on the new page in a new window, but the custom sized-window is also opened as a blank page.
<form action="Upload.cfm" target="_blank" enctype="multipart/form-data" method="post" onSubmit="window.open('', 'mywindow3','left=0,width=900,height=600,z-index=20, resizable=yes, scrollbars=yes');">
If i remove the onSubmit javascript, it just opens a new tab (again, not what I want). If i remove the target="_blank"
, it just opens a new tab as well.
What I really want to do is have the window.open
dimensions in my onSubmit event apply to the submitted form page, not an extraneous blank page.
- If my post is unclear, the above code opens 2 pop-up windows (1 good, 2 bad). The custom-sized one is not the page the form submits too, unfortunately. The one the page submits to is a little smaller. – MeanDean73 Commented Mar 6, 2015 at 16:31
2 Answers
Reset to default 4You can do something like this:
Set the action normally, set a custom name for the target
attribute and set the button
type to button
, not submit
(we will submit by javascript):
<form id="myform" method="post" enctype="multipart/form-data" action="Upload.cfm" target="result">
<input type="text" name="test" value="test">
<button type="button" id="mybutton">Send</button>
</form>
Set a "click" event to the button
and, in the callback, open the window with window.open()
and set the first parameter as the form's action and the second parameter as the form's target as well as the dimensions and furthermore attributes. And then submit the form!
document.getElementById('mybutton').addEventListener('click', function(){
window.open('Upload.cfm', 'result', 'width=300,height=300');
document.getElementById('myform').submit();
});
I've tested this in latest Firefox and Chrome.
A (bit) simpler version and explanation than the answer above, imo:
<form action="Upload.cfm" method="POST" target="customWindow">
<input type="text" name="test" value="test">
<button onclick="window.open('Upload.cfm', 'customWindow', 'width=900,height=600'); $(this).closest('form').submit();">
SUBMIT
</button>
</form>
本文标签: javascriptSubmit form to new custom size windowStack Overflow
版权声明:本文标题:javascript - Submit form to new custom size window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744090335a2531912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论