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.U开发者_高级运维RL 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?
var regex = new RegExp("/deals/new$");
if(document.URL.match(regex))
alert("yeah");
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(/|$)"
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
.
精彩评论