I'm creating a javascript app for sharepoint, and I need to get the url of this app. The same url that is in content of site.

I need another solution because when i try to simply reload the page with javascript, the browser cache return old variables populated and I get error in my communication with lists.

I want something like this:

location.href = context.thisAppUrl;
  • Isn't it available in the query string? Nov 27, 2014 at 13:15
  • Now I saw, yes it is. I'll try to catch him
    – Joao Paulo
    Nov 27, 2014 at 13:18

2 Answers 2

function manageQueryStringParameter(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];

var hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
var appWebUrl = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));

With "_spPageContextInfo" you can get all properties of app.

If you want only url of APP :

var AppWebUrl = _spPageContextInfo.webAbsoluteUrl;

this code is the same of appweburl in query parameter.

But to get SPHostUrl try the method getQueryStringParameter(valueString)

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

function getQueryStringParameter(value) {

    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] == urlParameterKey)

            return decodeURIComponent(singleParam[1]);



Hope this help.

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.