streetparade
streetparade

Reputation: 32908

document.URL Matching in Javascript

I have a url which looks like this https://test.high.com/people/11111111-name-firstname-_custa/deals/new

Now i need to match document.URL if im on that Page if so i will alert a message.

The important part is /deals/new

How can i match that in Javascript?

Upvotes: 0

Views: 4235

Answers (3)

Amarghosh
Amarghosh

Reputation: 59461

var regex = new RegExp("/deals/new$");
if(document.URL.match(regex))
  alert("yeah");

Upvotes: 2

Jens
Jens

Reputation: 25593

A Regex matching any string ending with "/deals/new" is

"/deals/new$"

If you need your link to only contain /deals/new, try

"/deals/new(/|$)"

Upvotes: 2

Sean Kinsey
Sean Kinsey

Reputation: 38046

Do you mean that you want access to the documents url from javascript?

That is done via the documents location property. Try document.location.href or only location.href.

Upvotes: -1

Related Questions