Js 使用Post方式传参并跳转到新页面

 2019-07-17 19:28:58   {{zan}}   0   172 

Js 使用Post方式传参并跳转到新页面

<script>
    function openNewWindowByPost(url,data){
        var newForm = document.createElement("form");
        newForm.id = "newForm";
        newForm.method = "post";
        newForm.action = url;
        newForm.target="_blank";//打开新页面
        var hideInput1 = document.createElement("input");
        hideInput1.type = "hidden";
        hideInput1.name="data";
        hideInput1.value = data;
        // 可以新加参数
        // var hideInput2 = document.createElement("input");
        // hideInput2.type = "hidden";
        // hideInput2.name="type";
        // hideInput2.value = type;
        // var hideInput3 = document.createElement("input");
        // hideInput3.type = "hidden";
        // hideInput3.name="language";
        // hideInput3.value = language;
        newForm.appendChild(hideInput1);
        // newForm.appendChild(hideInput2);
        // newForm.appendChild(hideInput3);
        if(document.all){
            newForm.attachEvent("onsubmit",function(){});//IE
        }else{
            var subObj = newForm.addEventListener("submit",function(){},false);//firefox
        }
        document.body.appendChild(newForm);
        if(document.all){
            newForm.fireEvent("onsubmit");
        }else{
            newForm.dispatchEvent(new Event("submit"));
        }
        newForm.submit();
        document.body.removeChild(newForm);
    }
</script>


亲测管用!

本文链接地址,转载请标注:https://caohongyuan.cn/article/119

(邮箱不会公开,只会做回复通知用) 提交 清空 {{comment.content}}
Re:{{response.content}}