Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Created January 28, 2013 23:01
Show Gist options
  • Select an option

  • Save chrisobriensp/4660107 to your computer and use it in GitHub Desktop.

Select an option

Save chrisobriensp/4660107 to your computer and use it in GitHub Desktop.
Shows a possible way of working around the apparent bug in SP2013 apps, where the SPHostUrl parameter value is incorrect on subsequent navigation to the app default page.
function sharePointReady() {
// retrieve passed app web/host web URLs..
if (_spPageContextInfo != undefined) {
// allow this code to be used in an app part page..
appweburl = _spPageContextInfo.webAbsoluteUrl;
if ((document.referrer !== "") && (!document.referrer.toLowerCase().startsWith(appweburl.toLowerCase()) && ($.getUrlVar("SPHostUrl")))) {
// we came from outside app web and are being passed SPHostUrl, so this should be the correct value - let's
// store it in a cookie against this path..
hostweburl = decodeURIComponent($.getUrlVar("SPHostUrl"));
var x = appweburl.replace('://', '');
var cookiePath = x.substr(x.indexOf('/'), x.length - x.indexOf('/'));
COB.cookieHandler.setCookie(cookieName, hostweburl, null, cookiePath);
}
else {
hostweburl = COB.cookieHandler.getCookie(cookieName);
}
}
else {
hostweburl = COB.cookieHandler.getCookie(cookieName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment