js windows.open()模拟POST提交

        function openPostWindow (url,name, data1, data2)
        {
            var tempForm = document.createElement("form");
            tempForm.id = "tempForm1";
            tempForm.method = "post";
            tempForm.action = url;
            tempForm.target=name;
            
            var hideInput1 = document.createElement("input");
            hideInput1.type = "hidden";
            hideInput1.name="data1";
            hideInput1.value = data1;
            
            var hideInput2 = document.createElement("input");
            hideInput2.type = "hidden";
            hideInput2.name="data2";
            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);
        }

posted on 2017-01-05 11:29  大牛叔叔  阅读(395)  评论(0编辑  收藏  举报