js获取地址栏参数

//获取地址栏参数
    getParam:function(name){
        var search = decodeURIComponent(document.location.search);
        var pattern = new RegExp("[?&]" + name + "=([^&]+)", "g");
        var matcher = pattern.exec(search);
        var items = null;
        if (null != matcher) {
            try {
                items = decodeURIComponent(decodeURIComponent(matcher[1]));
            } catch (e) {
                try {
                    items = decodeURIComponent(matcher[1]);
                } catch (e) {
                    items = matcher[1];
                }
            }
        }
        return items;
    },

 

posted @ 2019-09-20 12:31  古墩古墩  Views(144)  Comments(0Edit  收藏  举报