window.open() 以post方式下載文件


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);
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM