Search This Blog

Monday, September 4, 2017

Get query string from javascript


By using the below code we can get the query string value & we can pass it to new URL.

var QuerystringID = getParameterByName("ID");
if(QuerystringID != "")
{
window.location = "<NewUrl>?DID="+ QuerystringID ;
}

//below function get the query string value from URL
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, " "));
}

No comments:

Post a Comment