jquery - get url path?

后端 未结 5 512
谎友^
谎友^ 2020-12-08 15:37

I know I can use window.location.pathname to return a url, but how do I parse the url?

I have a url like this: http://localhost/messages/mine/9889 and I\'m trying to

5条回答
  •  鱼传尺愫
    2020-12-08 16:18

    if (window.location.pathname.split("/")[2] == "mine") {
      // it exists
    };
    

    window.location.pathname is a string at the end of the day, so the usual string methods apply.

提交回复
热议问题