I ran into an error while trying to gain access to the required libraries for JavaScript development. I copied this code straight from Microsoft's documentation, however when it is executed on my page through a content editor web part, I get the following error:

Unable to get property 'split' of undefined or null reference

It doesn't like the split call in the getQueryStringParameter() function. What exactly is the function trying to do with my document.URL, and what does the URL not have that causes it to not get processed properly?

<script type="text/javascript">
var hostweburl;

// Load the required SharePoint libraries.
$(document).ready(function () {

    // Get the URI decoded URLs.
    hostweburl =

    // The js files are in a URL in the form:
    // web_url/_layouts/15/resource_file
    var scriptbase = hostweburl + "/_layouts/15/";

    // Load the js files and continue to
    // the execOperation function.
    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", execOperation);

// Function to execute basic operations.
function execOperation() {

    // Continue your program flow here.


// Function to retrieve a query string value.
// For production purposes you may want to use
// a library to handle the query string.
function getQueryStringParameter(paramToRetrieve) {
    var params =
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == paramToRetrieve)
            return singleParam[1];



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.