Organizational Research By

Surprising Reserch Topic

How do i can get query string values in JavaScript?


Is there a plugin-less way of retrieving query string values via jQuery (or without)?

If so, how? If not, is there a plugin which can do so?

asked Jun 30, 2015 in JAVASCRIPT by rajesh
0 votes
81 views



Related Hot Questions

1 Answer

0 votes

You don't need jQuery for that purpose. You can use just some pure JavaScript:

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, " "));
}

Usage:

var prodId = getParameterByName('prodId');
answered Jun 30, 2015 by rajesh

...