Saturday, May 21, 2016

Get App Web and Host Web URL using jQuery

Find below the code sample of jQuery to get App Web and Host web URL.

$(document).ready(function(){
var spHostWebUrl=decodeURIComponent(getQueryStringValue("SPHostUrl"));
var spAppWebUrl=decodeURIComponent(getQueryStringValue("SPAppWebUrl"));
console.log("Host web URL  :"+spHostWebUrl);
console.log("App web URL  :"+spAppWebUrl);
});

function getQueryStringValue(paramName){
var params=document.URL.split("?")[1].split("&");
for(var intx=0;intx<params.length;intx++){
var urlParam=params[intx].split("=");
if(urlParam[0]==paramName){
return urlParam[1];
}
}
}

No comments:

Post a Comment