3

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

Assume 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

5
  • Is that a SharePoint hosted app or provider hosted app? Also provide your code that you are trying... Commented Apr 19, 2016 at 10:59
  • It is a Sharepoint hosted app Commented Apr 19, 2016 at 11:07
  • So I've added the code in a image above. Above the ajax call I'm just trying a bunch of stuff. I've also found some stuff while searching and it looks like I should be trying to get the SPHostUrl. Commented Apr 19, 2016 at 11:15
  • try this url --> var url = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items" Commented Apr 19, 2016 at 11:25
  • The problem is that the _spPageContextInfo.siteAbsoluteUrl returns app-(randomid).sharepointapp.com and I want sharepoint.com, or at least that is what I think i need. Commented Apr 19, 2016 at 11:51

2 Answers 2

1

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.

2
  • Thank you very much, This solved the problem splendidly! Commented Apr 19, 2016 at 12:57
  • Please upvote my answer....glad to help you. Commented Apr 19, 2016 at 13:00
0

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.