SoFunction
Updated on 2025-03-03

js get url parameter code instance sharing (JS operation URL)


var LG=(function(lg){
    var objURL=function(url){
        =url||;
="";//?The previous part
={};//url parameter object
="";//# and the following part
        ();
    }
//Analyze the url and get? The parameters are saved first, and the parameters are resolved as objects, and the # number and the subsequent ones are saved
    =function(){
        var str=;
        var index=("#");
        if(index>0){
            =(index);
            str=(0,index);
        }
        index=("?");
        if(index>0){
            =(0,index);
            str=(index+1);
            var parts=("&");
            for(var i=0;i<;i++){
                var kv=parts[0].split("=");
                [kv[0]]=kv[1];
            }
        }
        else{
            =;
            ={};
        }
    }
//Just modify
    =function(key,val){
        [key]=val;
    }
//Just set
    =function(key){
        [key]=undefined;
    }
//The url after the operation is composed according to three parts
    =function(){
        var strurl=;
var objps=[];//This is organized using an array, and then do join operations
        for(var k in ){
            if([k]){
                (k+"="+[k]);
            }
        }
        if(>0){
            strurl+="?"+("&");
        }
        if(>0){
            strurl+=;
        }
        return strurl;
    }
//Get parameter value
    =function(key){
        return [key];
    }   
    =objURL;
    return lg;
}(LG||{}));