开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜