1、正常下載文件
window.open("url", "_blank");
2.post方式
function openPostWindow(url, data) { var tempForm = document.createElement("form"); tempForm.id = "tempForm1"; tempForm.method = "post"; tempForm.action = url; tempForm.target = "_blank"; //打開新頁面 var hideInput1 = document.createElement("input"); hideInput1.type = "hidden"; hideInput1.name = "accounts"; //后台要接受這個參數來取值 hideInput1.value = data; //后台實際取到的值 /*var hideInput2 = document.createElement("input"); hideInput2.type = "hidden"; hideInput2.name="xtmc"; hideInput2.value = data2;*/ //這里就是如果需要第二個參數的時候可以自己再設置 tempForm.appendChild(hideInput1); //tempForm.appendChild(hideInput2); if (document.all) { tempForm.attachEvent("onsubmit", function () { }); //IE } else { var subObj = tempForm.addEventListener("submit", function () { }, false); //firefox } document.body.appendChild(tempForm); if (document.all) { tempForm.fireEvent("onsubmit"); } else { tempForm.dispatchEvent(new Event("submit")); } tempForm.submit(); document.body.removeChild(tempForm); }