js实现页面跳转的两种方式

CreateTime--2017年8月24日08:13:52
Author:Marydon

js实现页面跳转的两种方式

方式一:

  window.location.href = url

说明:我们常用来在js中实现页面跳转的方法,使用get方式发送请求,传参有限

更多介绍,见文章:js操作当前窗口  

方式二:

  通过POST请求实现页面跳转

/**
 * 发送POST请求跳转到指定页面
 * @param URL
 *         跳转路径
 * @param PARAMS
 *        参数:格式-JSON对象
 */
function httpPost(URL, PARAMS) {
    var temp = document.createElement("form");
    temp.action = URL;
    temp.method = "post";
    temp.style.display = "none";
    for (var x in PARAMS) {
        var opt = document.createElement("textarea");
        opt.name = x;
        opt.value = PARAMS[x];
        temp.appendChild(opt);
    }
    document.body.appendChild(temp);
    temp.submit();
    return temp;
}
原文地址:https://www.cnblogs.com/Marydon20170307/p/7421228.html