JSFiddle - React, Tailwind, and code Playground

by JThomas

HTML

<input type="text" id="username" />

JavaScript

window.ParseQueryString = function () {
    //Get the current location in the address bar
    var url = window.location.href + '?username=Francesca',
        parameterSet = {},
        //Get everything to the right of the '?'
        parameterString = url.split('?')[1];

    //Do we have anything to work with?
    if (parameterString) {
        //Lets get all individual parameter in the parameter string
        var parameterParts = parameterString.split('&');

        for (var i = 0, e; e = parameterParts[i++];) {
            //Get the parameter key and the value
            var parameter = e.split('=');

            //Add a new field to the object
            parameterSet[parameter[0]] = parameter[1];
        }
    }

    //Give me my prettyfied query string array plz!
    return parameterSet;
}


var q = ParseQueryString();

document.getElementById("username").value = q.username;