js解析地址栏参数

/**
 * 获取地址栏中url后面拼接的参数
 * eg:
 *   浏览器地址栏中的地址:http://1.1.1.1/test.html?owner=2db08226-e2fa-426c-91a1-66e26f62c13f&view=pc
 *   var param=location.search;//?owner=2db08226-e2fa-426c-91a1-66e26f62c13f&view=pc
 *   var ownerId = getUrlParam("owner",param);
 *   var view = getUrlParam("view",param);
 */
function getUrlParam(name,param) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 
    var r = param.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

 

posted @ 2019-05-27 16:46  Goatherd  阅读(1050)  评论(0编辑  收藏  举报