fhefh2015
8/25/2016 - 2:35 AM

获取URL搜索字符串参数

获取URL搜索字符串参数

  function urlArags() {
        var args = {};
        var query = window.location.search.substring(1);
        var pairs = query.split("&");

        for (var i = 0, len = pairs.length; i < len; i++) {
            var pos = pairs[i].indexOf('=');

            if (pos == -1) {
                continue;
            }

            var name = pairs[i].substring(0, pos);
            var value = pairs[i].substring(pos + 1);
            value = decodeURI(value);

            args[name] = value;
        }

        return args;
    }

    //http://localhost:63342/tmp/tmp/temp/other/1.html?_ijt=8t901hce6v4nsibcmics01301l&ssc=1&adsd=1212
    var result = urlArags();
    console.log(result);