window.open () to post a file to download

1, the normal download file

 window.open("url", "_blank");

2.post way

 function openPostWindow (URL, Data) {
             var tempForm = document.createElement ( "form" ); 
            tempForm.id = "tempForm1" ; 
            tempForm.method = "POST" ; 
            tempForm.action = URL; 
            tempForm.target = "_blank"; // open a new page 
            var hideInput1 = document.createElement ( "the INPUT" ); 
            hideInput1.type = "hidden" ; 
            hideInput1.name = "Accounts"; // backstage to accept this parameter to the value 
            hideInput1.value = data;// background to take the actual value
            / * Var hideInput2 = document.createElement ( "INPUT"); 
            hideInput2.type = "hidden"; 
            hideInput2.name = "xtmc"; 
            hideInput2.value = DATA2; * /   // this is the second time if desired parameter may then set their 
            tempForm.appendChild (hideInput1);
             // tempForm.appendChild (hideInput2); 
            IF (the document.all) { 
                tempForm.attachEvent ( "the onsubmit", function () {});         // IEs 
            } the else {
                 var subObj tempForm.addEventListener = ( "Submit", function () {}, to false);    //firefox
            }
            document.body.appendChild(tempForm);
            if (document.all) {
                tempForm.fireEvent("onsubmit");
            } else {
                tempForm.dispatchEvent(new Event("submit"));
            }
            tempForm.submit();
            document.body.removeChild(tempForm);
        }

 

Guess you like

Origin www.cnblogs.com/fightingkaikai/p/11307055.html