Skip to main content
edited tags
Link
variable
  • 4.4k
  • 13
  • 76
  • 139
Source Link
variable
  • 4.4k
  • 13
  • 76
  • 139

Javascript on masterpage returns undefined

_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.