Get the current URL with JavaScript?

后端 未结 23 1908
梦谈多话
梦谈多话 2020-11-21 07:08

All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a va

23条回答
  •  孤独总比滥情好
    2020-11-21 07:37

    Firstly check for page is loaded completely in

    browser,window.location.toString();
    
    window.location.href
    

    then call a function which takes url, URL variable and prints on console,

    $(window).load(function(){
       var url = window.location.href.toString();
       var URL = document.URL;
       var wayThreeUsingJQuery = $(location).attr('href');
       console.log(url);
       console.log(URL);
       console.log(wayThreeUsingJQuery );
    });
    

提交回复
热议问题