Javascript在表单上发布提交打开一个新窗口

https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit向您展示了如何提交一个您通过JavaScript创建的表单。 以下是我修改的代码。

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");

var hiddenField = document.createElement("input");      
hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form);    // Not entirely sure if this is necessary           
form.submit();

我想要做的是在新窗口中打开结果。 我现在正在使用类似的东西在新窗口中打开一个页面:

onclick=window.open(test.html,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

<form target="_blank" ...></form>

要么

form.setAttribute("target", "_blank");

到你表单的定义。


如果你想创建并提交你的问题,你的问题是你的形式,并且你想创建自定义功能的弹出窗口,我建议这个解决方案(我把注释放在我添加的上面):

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");

// setting form target to a window named 'formresult'
form.setAttribute("target", "formresult");

var hiddenField = document.createElement("input");              
hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form);

// creating the 'formresult' window with custom features prior to submitting the form
window.open('test.html', 'formresult', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

form.submit();

var urlAction = 'whatever.php';
var data = {param1:'value1'};

var $form = $('<form target="_blank" method="POST" action="' + urlAction + '">');
$.each(data, function(k,v){
    $form.append('<input type="hidden" name="' + k + '" value="' + v + '">');
});
$form.submit();
链接地址: http://www.djcxy.com/p/21933.html

上一篇: Javascript Post on Form Submit open a new window

下一篇: How do you post to an iframe?