Get escaped URL parameter

后端 未结 19 2682
小蘑菇
小蘑菇 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:45

    Below is what I have created from the comments here, as well as fixing bugs not mentioned (such as actually returning null, and not 'null'):

    function getURLParameter(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
    }
    

提交回复
热议问题