Skip to content

Instantly share code, notes, and snippets.

@dhunmoon
Created December 22, 2015 18:59
Show Gist options
  • Save dhunmoon/d923fd4134a39bb6bd52 to your computer and use it in GitHub Desktop.
Save dhunmoon/d923fd4134a39bb6bd52 to your computer and use it in GitHub Desktop.
SharepointL Root Site URL
//HOW TO GET SITE URL
document.location.origin + _spPageContextInfo.webServerRelativeUrl
//CODE TO GET SITE DOMAIN SITE URL AND SITE RELATIVE URL
//GETTING SITE URL
ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");
function getWebProperties() {
var ctx = new SP.ClientContext.get_current();
this.web = ctx.get_web();
ctx.load(this.web, 'Title', 'Id', 'Created', 'ServerRelativeUrl');
ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
} function onSuccess(sender, args) {
_relativeUrl = this.web.get_serverRelativeUrl();
_fullSiteUrl = document.location.origin + _relativeUrl;
} function onFail(sender, args) {
console.log('failed to get list. Error:' + args.get_message());
}
//EO: Getting SITE URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment