MultiDev
MultiDev

Reputation: 10649

Check to see if current url matches string

I am trying to see if a link to the current page's URL exists in a menu.

var thisUrl = window.location.href;

$("ul.leftmenu li a").each(function() { 

  var thisHref = $(this).attr('href');

  if (thisUrl === thisHref) { 

    // matches

  }

});

This works as long as the current window location URL does not contain any _GET variables. How would I modify this to ignore the _GET variables in the current address?

Upvotes: 3

Views: 647

Answers (1)

dfsq
dfsq

Reputation: 193261

You can remove query string part from the href. For example like this:

var thisUrl = window.location.href.replace(location.search, '');

location.search property represents GET parameters substring, i.e. ?param=value&param2=etc.

Upvotes: 6

Related Questions