Are you first timer at 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
added Jul 6 in Javascript by LC Marshal Lieutenant (14,570 points)
edited Jul 12 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. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.