Javascript 提交表单到弹出窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7353838/
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
Submit form to popup window?
提问by Jonah Katz
I have a script that submits a form to a popup window but instead of displaying the form's action (process.php), it displays nothing (blank window). Heres my script:
我有一个将表单提交到弹出窗口的脚本,但它没有显示表单的操作 (process.php),而是什么都不显示(空白窗口)。这是我的脚本:
function redirectOutput() {
var myForm = document.getElementById('formID');
var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusb
ar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
myForm.target = 'Popup_Window';
return true;
}
回答by pimvdb
It works, but you have a newline suddenly in your window.open
.
它有效,但是您的window.open
.
This works just fine for me: http://jsfiddle.net/pimvdb/N3YSG/.
这对我来说很好用:http: //jsfiddle.net/pimvdb/N3YSG/。
var myForm = document.getElementById('formID');
myForm.onsubmit = function() {
var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
this.target = 'Popup_Window';
};
回答by ramiz
An easy way to submit form in popup window:
在弹出窗口中提交表单的简单方法:
HTML:
HTML:
<form action="..." method="post" onsubmit="target_popup(this)">
<!-- form fields etc here -->
</form>
Javascript:
Javascript:
function target_popup(form) {
window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
form.target = 'formpopup';
}
Source: http://www.electrictoolbox.com/post-form-popup-window-javascript-jquery/
来源:http: //www.electrictoolbox.com/post-form-popup-window-javascript-jquery/
回答by Naftali aka Neal
Why dont you just do it inside of the <form>
?
你为什么不在里面做呢<form>
?
<form target="_blank">...</form>