js to get the GET of the URL

A function I saw in the pdf.js project seems to be very reliable. I tried it myself, adjusted it, and it works now. The code is as follows:

 

/**
 * Helper function to parse query string (e.g. ?param1=value&parm2=...).
 */
function parseQueryString(query) {
    query = query ? query : document.location.search.substring(1);
    if (!query) return {};
    var parts = query.split('&');
    var params =};
    for (var i = 0, ii = parts.length; i < ii; ++i) {
        var param = parts [i] .split ('=');
        var key = param [0] .toLowerCase ();
        var value = param.length > 1 ? param[1] : null;
        params[decodeURIComponent(key)] = decodeURIComponent(value);
    }
    return params;
}

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326945457&siteId=291194637