views:

77

answers:

3

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?

A: 

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.

Sean Kinsey
+1  A: 

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(/|$)"
Jens
don't forget escaping: `/\/deals\/new$/`
nickf
+2  A: 
var regex = new RegExp("/deals/new$");
if(document.URL.match(regex))
  alert("yeah");
Amarghosh
Thanks this worked for me have a nice day
streetparade