将表单提交到弹出窗口?

时间:2011-09-08 20:09:05

标签: javascript

我有一个脚本将表单提交到弹出窗口但不显示表单的操作(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;
}

3 个答案:

答案 0 :(得分:28)

虽然有效,但您的window.open突然出现换行符。

这对我来说很合适: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';
};

答案 1 :(得分:13)

在弹出窗口中提交表单的简便方法:

HTML:

<form action="..." method="post" onsubmit="target_popup(this)">
    <!-- form fields etc here -->
</form>

使用Javascript:

function target_popup(form) {
    window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
    form.target = 'formpopup';
}

来源: http://www.electrictoolbox.com/post-form-popup-window-javascript-jquery/

答案 2 :(得分:2)

为什么不在<form>

内进行
<form target="_blank">...</form>