How to get current site url in sharepoint using javascript


using javascript



You just add the below code in script editor or the js file in an app

//--------------------------------------------
   <script type="text/javascript">
        
            function Test() {
                currentcontext = new SP.ClientContext.get_current();
                var Sitecol_url = window.location.protocol + '//' + window.location.host;
                var PageURL = Sitecol_url + currentcontext.get_url();
                 }
                 
        </script>

//------------------------------