Get QueryString values in JavaScript


How to get QueryString values in JavaScript and jQuery?

For. Example:

URL: https://flipkart.com/shoppingcart/productdetails.aspx?orderId=32456&userId=ax128992242

Here, How to get the value of ‘orderid’ in your client side scripts like JavaScript or jQuery? In ASP.NET you can use Request.QueryString[“orderid”] to retrieve the query string values from URL.

Please use the following method.

Method:

function getQuerystring(param, default_) {
if (default_ == null) default_ = "";
param= param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + param + "=([^&#]*)");
var qsValue = regex.exec(window.location.href);
if (qsValue  == null)
return default_;
else
return qsValue [1];
}

Code:

var _orderProductRecordID = getQuerystring('orderId');