_spBodyOnLoadFunctionNames.push("FetchURL");
function FetchURL()
{
// Custom JavaScript methods
var ctx = new SP.ClientContext();
var site = ctx.get_site();
ctx.load(site);
ctx.executeQueryAsync(function(s, a){ currURL=SP.Utilities.Utility.getLayoutsPageUrl("");
});
}
The above method returns the URL, however, sometimes it returns undefined, which causes errors. How to tackle this?
Code is placed in head of the masterpage... in scripts tag.
undefined
? The function FeetchURL has no return and will then always returnunderfined
. The global variablecurrURL
will be set asynchronously, asctx.executeQueryAsync
is asynchronous, which means in you code you can't know when it is set