DNK Gif

Dot Net Knowledge

Labels

Sunday, 17 April 2016

Find Out the Parameter value from the Query String in the URL using JavaScript

How to find Out the Parameter value from the Query String in the URL?

Here is the Code to do this-

function GetParameterValues(param) {
    var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < url.length; i++) {
        var urlparam = url[i].split('=');
        if (urlparam[0].toLowerCase() == param.toLowerCase()) {
            return urlparam[1];
        }
    }
}

Use:

<script>
 var name = GetParameterValues('name');
var id = GetParameterValues('ID');
alert("Hello " + name + " your ID is " + id);
</script>

No comments:

Post a Comment