Get escaped URL parameter

后端 未结 19 2703
小蘑菇
小蘑菇 2020-11-21 13:41

I\'m looking for a jQuery plugin that can get URL parameters, and support this search string without outputting the JavaScript error: \"malformed URI sequence\". If there is

19条回答
  •  忘了有多久
    2020-11-21 13:57

    Slight modification to the answer by @pauloppenheim , as it will not properly handle parameter names which can be a part of other parameter names.

    Eg: If you have "appenv" & "env" parameters, redeaing the value for "env" can pick-up "appenv" value.

    Fix:

    var urlParamVal = function (name) {
        var result = RegExp("(&|\\?)" + name + "=(.+?)(&|$)").exec(location.search);
        return result ? decodeURIComponent(result[2]) : "";
    };
    

提交回复
热议问题