I have a SharePoint hosted app and I am trying to pull the SPHostUrl out of the app Url for REST calls.

Everything I read tells me to use the below but for some reason I am getting an error

'GetQueryStringParameter' is undefined

I have tried in a couple of different browsers and even tried just a simple command in the console using the browser developer tools but it seems GetQueryStringParameter() is not a valid function? am I missing something?



References in Default.aspx

<script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="../Scripts/App.js"></script>

Line in App.js

var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));

1 Answer 1


Definition of getQueryStringParameter should look like following. Check it in your App.js file.

function getQueryStringParameter(paramToRetrieve) {
var params =
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] == paramToRetrieve)
        return singleParam[1];

It is not needed actually, you can get by following way.

var spHostUrl = GetUrlKeyValue('SPHostUrl');

See following post for more explanation by Danny Engelman



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.