Question

I am developing a sharepoint app (add-in) but I'm pretty new to sharepoint over all and need some help.

Asume that I am hosting the app on app-(app_id).sharepointapp.com and from that app I want to call a function or something which returns sharepoint.com which is the actual site (might be called test-site or something like that).

I have been trying to use _spPageContextInfo but I can't find a good match.

PS: Sorry if I've completely battered the SharePoint terminology.

enter image description here

Était-ce utile?

La solution

Using below methods you will get SPHostUrl and SPAppWebUrl. In hostweb you will get your "sharepoint.com" url.

// read URL parameters
function getQueryStringParameter(param) {
  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] == param) {
      return singleParam[1];
    }
  }
}

$(document).ready(function () {
  // get the URLs of the host web and the app web
  SPAppWebUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
  SPHostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
});

You can take reference from this link.

Hope this will help you.

Autres conseils

SP.PageContextInfo.get_siteAbsoluteUrl(), will give you the Site Collection URL.

SP.PageContextInfo.get_webAbsoluteUrl(), will give you the Site (or subsite) URL.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top