首页 > 代码库 > window.open打开新窗体并用post方式传参

window.open打开新窗体并用post方式传参

function openPostWindow(url,data,name){  //url要跳转到的页面,data要传递的数据,name新窗体名          var tempForm = document.createElement("form");            tempForm.id="tempForm1";            tempForm.method="post";            tempForm.action=url;            tempForm.target=name;            var hideInput = document.createElement("input");            hideInput.type="hidden";            hideInput.name= "dataname"          hideInput.value= data;          tempForm.appendChild(hideInput);             tempForm.attachEvent("onsubmit",function(){ openWindow(name); });//必须用name不能用url,否则无法传值到新页面          document.body.appendChild(tempForm);                     tempForm.fireEvent("onsubmit");          tempForm.submit();          document.body.removeChild(tempForm);}function openWindow(name)  {       var iWidth=1100; //弹出窗口的宽度;     var iHeight=550; //弹出窗口的高度;     var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;     var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;             window.open(‘about:blank‘,name,"height="+iHeight+", width="+iWidth+", top="+iTop+", left="+iLeft+",toolbar=no, menubar=no,  scrollbars=yes,resizable=yes,location=no, status=no");  }  

在新页面中:String data = http://www.mamicode.com/(String)request.getParameter("dataname"); //获取上个页面传入的值

window.open打开新窗体并用post方式传参