开发者

document.URL Matching in Javascript

开发者 https://www.devze.com 2022-12-28 23:15 出处:网络
I have a url which looks like this https://test.high.com/people/11111111-name-firstname-_custa/deals/new

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

精彩评论

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

关注公众号