JS - Give condition when specific parameter exist in URL

0 votes
213 views
added Jul 6, 2018 in Javascript by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 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
}
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...