jQuery - if url matched condition

0 votes
31,357 views
added May 8, 2019 in Javascript by LC Marshal Captain (25,770 points)
retagged May 8, 2019 by LC Marshal
if(window.location.href === "https://lazacode.org/add?cat=84") {
    //do this
}

 

1 Response

0 votes
responded May 8, 2019 by LC Marshal Captain (25,770 points)
var url = window.location.href,
    last_part = url.substring(url.lastIndexOf('/') + 1);
    if ($('body').hasClass('isdesktop')) {
      if(last_part == 'news') {
        $('#mega-menu-main-menu li:first-child a').addClass('active');   
      }
      else if (last_part == 'search?field_category_value=news&combine=') {
        $('#mega-menu-main-menu li:nth-child(2) a').addClass('active');   
      }
      else if (last_part == 'search?field_category_value=indepth&combine=') {
        $('#mega-menu-main-menu li:nth-child(3) a').addClass('active'); 
      }
      else if (last_part == 'search?field_category_value=lifestyle&combine=') {
        $('#mega-menu-main-menu li:nth-child(4) a').addClass('active'); 
      }
      else if (last_part == 'search?field_category_value=%E6%96%B0%E9%97%BB&combine=') {
        $('#mega-menu-main-menu li:nth-child(5) a').addClass('active'); 
      }
      else if (last_part == 'pullout') {
        $('#mega-menu-main-menu li:nth-child(6) a').addClass('active'); 
      }
      else if (last_part == 'edgeproptv') {
        $('#mega-menu-main-menu li:nth-child(7) a').addClass('active'); 
      }
      else if (last_part == 'events') {
        $('#mega-menu-main-menu li:nth-child(8) a').addClass('active'); 
      }
    }

 

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