How can I get query string values in JavaScript?

We have may plug-ins to read Query string values in JavaScript. But we don’t know what is happening inside plug-in.

let’s learn how to read Query String values with plain JavaScript.

Example URL:

Script to read Query String Value.

<script type="text/javascript">
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(;
        return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

Method Call:

  1. var postNo = getParameterByName("PostNo");//OutPut:100

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s