Get escaped URL parameter

后端 未结 19 2704
小蘑菇
小蘑菇 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 14:02

    Based on the 999's answer:

    function getURLParameter(name) {
        return decodeURIComponent(
            (location.search.match(RegExp("[?|&]"+name+'=(.+?)(&|$)'))||[,null])[1]
        );  
    }
    

    Changes:

    • decodeURI() is replaced with decodeURIComponent()
    • [?|&] is added at the beginning of the regexp

提交回复
热议问题