window.open模拟表单POST提交

解决地址栏长度限制,隐藏参数,不在地址栏显示
项目 excel 导出中用到
将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中 var url=“XXX”;
var tempForm = document.createElement("form");
tempForm.id="tempForm";
tempForm.method="post";
tempForm.action=url;
tempForm.target="blank";
//可以定义多个input 传多个参数
var hideInput = document.createElement("input"); hideInput.type="hidden";
hideInput.name="ids";
hideInput.value= ids;
tempForm.appendChild(hideInput);
if (tempForm.attachEvent) { // IE
tempForm.attachEvent("onsubmit",function(){ window.open('about:blank','blank'); });
} else if (tempForm.addEventListener) { }
// DOM Level 2 standard
tempForm.addEventListener("onsubmit",function(){ window.open('about:blank','blank')});
}
document.body.appendChild(tempForm);
if (document.createEvent) { }
// DOM Level 2 standard
evt = document.createEvent("MouseEvents");
evt.initMouseEvent("submit", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
tempForm.dispatchEvent(evt);
} else if (tempForm.fireEvent) { // IE tempForm.fireEvent('onsubmit');
}
//必须手动的触发
tempForm.submit();
document.body.removeChild(tempForm);
上一篇:win7 64位下自行编译OpenCV2.4.10+CUDA toolkit 5.5的整个过程以及需要注意的问题(opencv+cuda并行计算元素的使用)


下一篇:利用NSIS软件制作C#安装包