Get escaped URL parameter

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

    After reading all of the answers I ended up with this version with + a second function to use parameters as flags

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

提交回复
热议问题