Skip to content

Instantly share code, notes, and snippets.

@sksnips
Created December 24, 2015 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/40f4e4855257b38767ea to your computer and use it in GitHub Desktop.
Save sksnips/40f4e4855257b38767ea to your computer and use it in GitHub Desktop.
HTML snippet used to retrieve the SharePoint web title using jsom
<!-- HTML Content -->
<div id="myapp"></div>
<!-- Script Content -->
<script type='text/javascript'>
var oWeb;
function getwebtitle()
{
var clientContext = SP.ClientContext.get_current(); // equivalent to SPContext.Current
oWeb = clientContext.get_web(); //Gets the current Web Object
clientContext.load(oWeb);
clientContext.executeQueryAsync(onSucceeded,onFailed);
}
function onSucceeded()
{
document.getElementById("myapp").innerHTML = "<b>Web Title:</b> " + oWeb.get_title();
}
function onFailed(sender, args)
{
try
{
console.log('Error: ' + args.get_message());
}
catch (err)
{
}
}
ExecuteOrDelayUntilScriptLoaded(getwebtitle, "sp.js");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment