js windows.open()模拟POST提交

Posted 大牛叔叔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
        }









































以上是关于js windows.open()模拟POST提交的主要内容,如果未能解决你的问题,请参考以下文章