Get the parameter value of the url address

The frequency of use is very high, Baidu recorded it

$.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return encodeURI(r[2]); return null;
}

If you get the parameter information of the source url

getUrlParam=function(name,url){
    var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
    console.log(url.substr(url.indexOf("?")))
    var r=url.substr(url.indexOf("?")+1).match(reg);
    if(r!=null){
        return encodeURI(r[2]);
    }
    return null;
}
var _url=document.referrer;
Use: getUrlParam( "url",_url);

Note: Sometimes you will encounter Chinese garbled characters, just change encodeURI to decodeURI

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324825922&siteId=291194637