Get current URL with jQuery?

后端 未结 30 2261
你的背包
你的背包 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:17

    http://www.refulz.com:8082/index.php#tab2?foo=789
    
    Property    Result
    ------------------------------------------
    host        www.refulz.com:8082
    hostname    www.refulz.com
    port        8082
    protocol    http:
    pathname    index.php
    href        http://www.refulz.com:8082/index.php#tab2
    hash        #tab2
    search      ?foo=789
    
    var x = $(location).attr('');
    

    This will work only if you have jQuery. For example:

    
    
    
    
    

提交回复
热议问题