In this post, you will see how to get querystring value from a URL on client side by using javscript.
Javascript function
<script type="text/javascript">
QueryString = function (str) {
var url = window.location.search.substring(1).split('&');
for (var i = 0; i < url.length; i++) {
var Name = url[i].split('=');
if (Name[0] == str)
return Name[1];
}
};
</script>
<script type="text/javascript">
alert(QueryString("firstName"));
alert(QueryString("lastName"));
</script>
URL
http://www.aspxtutorial.com/demo/Jquery/QueryString.aspx?firstName=Aamir&lastName=Hasan
In the above URL, I have passed firstName and lastName querystring values.
Above you will notice that I have called querystring function twice and passed variable name to get value of querystring from URL.
Note: Function will return undefined if when there is no querystring is passed in the URL.
Above function has been tested on following browsers (IE, firefox, chrome, safari, ipad, iphone and opera)
Output

view demo