4

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?

URL

http://app-cb941ae4f1f18e.app.dragon.dev/sites/smrgol/AppPartTest/Pages/Default.aspx?SPHostUrl=http%3A%2F%2Flair%2Edragon%2Edev%2Fsites%2Fsmrgol&SPLanguage=en%2DUS&SPClientTag=2&SPProductNumber=15%2E0%2E4763%2E1000&SPAppWebUrl=http%3A%2F%2Fapp%2Dcb941ae4f1f18e%2Eapp%2Edragon%2Edev%2Fsites%2Fsmrgol%2FAppPartTest

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

6

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

function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1].split("&");
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

https://sharepoint.stackexchange.com/a/159290/21421

2

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.