Find URL and check segments

Find URL and check segments

Hi.

I am trying to get jQuery to find the current URL, and then use conditions to load a different variable depending on it.

For instance, if the first segment after the URL is empty, show this... if the first URL is equal to then show this.

www.domain.com/segment_1/segment_2 etc.

I have managed to get this to partically work using the following. But it only works for the first condition, not the second.

Can anyone point me in a better direction, or show me what I am doing wrong?

  1.             var url = window.location.href;
                var host = window.location.host;
               
                if (url.indexOf('http://' + host + '/') != -1) {
                    var path = '/index.php/greeting-cards/embed_grid_popup/'+$(this).attr("id");
                   } else if (url.indexOf('http://' + host + '/posters/') != -1) {
                    var path = '/index.php/posters/embed_grid_popup/'+$(this).attr("id");                  
                   }








Thank you