How to get query string values / URL Parameters in JavaScript? How to get query string values in JavaScript (URL Parameters)?

URLs parameters are the easiest way to pass the variables from one web page to the other web page. In this article, I will guide you to get the URL parameter in a simple manner.

Function to get query string values in JavaScript

<script type="text/javascript">
function getQueryStringVariable(variable)
  var query =;
  var vars = query.split("&");
  for(var i=0;i<vars.length;i++) 
    var pair = vars[i].split("=");
    if(pair[0] == variable){return pair[1];}




console.log(getQueryStringVariable('key1'));   // Output: value1

console.log(getQueryStringVariable('key2'));   // Output: value2

console.log(getQueryStringVariable('gowri'));   // Output: shankar


Leave a Reply

Your email address will not be published. Required fields are marked *

Sign In


Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.