将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中。
function openPostWindow(url, data, name){ var tempForm = document.createElement("form"); tempForm.id="tempForm1"; tempForm.method="post"; tempForm.action=url; tempForm.target=name; $.each(data,function(name,value) { var hideInput = document.createElement("input"); hideInput.type="hidden"; hideInput.name= name; hideInput.value= value; tempForm.appendChild(hideInput); }); if(document.all){ tempForm.attachEvent("onsubmit",function(){ openWindow(name); }); //IE }else{ var subObj = tempForm.addEventListener("submit",function(){ openWindow(name); },false); //firefox } document.body.appendChild(tempForm); if(document.all){ tempForm.fireEvent("onsubmit"); }else{ tempForm.dispatchEvent(new Event("submit")); } tempForm.submit(); document.body.removeChild(tempForm); } function openWindow(name){ window.open('about:blank',name,"height=600,width=800,top=20,left=20"); }