Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - Give condition when specific parameter exist in URL

0 votes
4 views
added Jul 6 in Javascript by LC Marshal First Warrant Officer (11,130 points)
edited 5 days ago by LC Marshal
//example page is here : http://localhost:8080/?uid=1&nid=12#/
function getUrlParam() {
    let params = {};
    let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        params[key] = value;
    });
    return params;
}
let loluid = getUrlParam()['uid'];

if(loluid == '1') {
  alert(`uid ${loluid} is here`);// output as uid 1 is here
}

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...