Get current URL with jQuery?

后端 未结 30 2277
你的背包
你的背包 2020-11-22 02:44

I am using jQuery. How do I get the path of the current URL and assign it to a variable?

Example URL:

http://localhost/menuname.de?foo=bar&nu         


        
30条回答
  •  灰色年华
    2020-11-22 03:25

    To get the path, you can use:

    var pathname = window.location.pathname; // Returns path only (/path/example.html)
    var url      = window.location.href;     // Returns full URL (https://example.com/path/example.html)
    var origin   = window.location.origin;   // Returns base URL (https://example.com)
    

提交回复
热议问题