Get Current SharePoint Site Url using javascript

<script>
var clientContext;
var website;
function GetSiteUrl()
  {
   clientContext = SP.ClientContext.get_current();
   website = clientContext.get_web();
   clientContext.load(website);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
  }
function onRequestSucceeded() {
alert(website.get_url());
}
function onRequestFailed(sender, args) {
alert('Error: ' + args.get_message());
}
</script>

<a href='javascript:GetSiteUrl();'>Get URL</a>

Comments

Popular posts from this blog

This content database has a schema version which is not supported in this farm

Export all documents/Folders permissions to CSV using SharePoint PowerShell

SPUtility.js