Get current URL with jQuery?

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

    Here is an example to get the current URL using jQuery and JavaScript:

    $(document).ready(function() {
    
        //jQuery
        $(location).attr('href');
    
        //Pure JavaScript
        var pathname = window.location.pathname;
    
        // To show it in an alert window
        alert(window.location);
    });
    
    
    $.getJSON("idcheck.php?callback=?", { url:$(location).attr('href')}, function(json){
        //alert(json.message);
    });
    

提交回复
热议问题