Get ClientContext in SharePoint App

Add the following function

[sourcecode language="javascript"]
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(;
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));


Then you can use this to get ClientContext

[sourcecode language="javascript"]
siteUrl = getParameterByName("SPAppWebUrl");

var clientContext = new SP.ClientContext(siteUrl);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.