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

IRM and the Object Model

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

Activate and Deactivate Feature through PowerShell