Get escaped URL parameter

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

    Just in case you guys have the url like localhost/index.xsp?a=1#something and you need to get the param not the hash.

    var vars = [], hash, anchor;
    var q = document.URL.split('?')[1];
    if(q != undefined){
        q = q.split('&');
        for(var i = 0; i < q.length; i++){
            hash = q[i].split('=');
            anchor = hash[1].split('#');
            vars.push(anchor[0]);
            vars[hash[0]] = anchor[0];
        }
    }
    

提交回复
热议问题