Archive

Posts Tagged ‘Javascript query string’

how to get query string parameters in javascript

August 18, 2014 Leave a comment
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Suppose url is
http://localhost:55218/Source/index.html?qProjectId=881&qType=build
We can get the value by calling

var projId = getParameterByName('qProjectId'); //881

Happy coding 🙂