js parsing URL parameters

js parses URL parameters:

url format: a=123&b=234

             getUrlParam(name) {
                    // Parse URL parameters
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");  
                    var locationHref = decodeURIComponent(window.location.search);
                    var r = locationHref.substr(1).match(reg);
                    if(r != null) {
                        if(unescape){
                            return unescape(r[2]);
                        }else{
                            return r[2];
                        }
                    }else{
                        return null;
                    }
                },    

usage:

To get the value of the parameter from the url, pass the corresponding parameter name in the method to return the parameter value.

 

Guess you like

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