We can easily get the query string value by accessing the window.location in JavaScript. The below code snippet provides a JavaScript function that reads the query string parameter password to the function
Considering below Url as an example,
http://www.ProgrammerGuide.Net/?technology=jquery&blog=jquerybyexample
You can simply call the JavaScript function below by passing the query string variable name:
01 | function GetQueryStringParams(sParam) |
02 | { |
03 | var sPageURL = window.location.search.substring(1); |
04 | var sURLVariables = sPageURL.split( '&' ); |
05 | for ( var i = 0; i < sURLVariables.length; i++) |
06 | { |
07 | var sParameterName = sURLVariables[i].split( '=' ); |
08 | if (sParameterName[0] == sParam) |
09 | { |
10 | return sParameterName[1]; |
11 | } |
12 | } |
13 | } |
Considering below Url as an example,
http://www.ProgrammerGuide.Net/?technology=jquery&blog=jquerybyexample
You can simply call the JavaScript function below by passing the query string variable name:
1 | // |
2 | var tech = GetQueryStringParams( 'technology' ); |
3 | var blog = GetQueryStringParams( 'blog' ); |
4 | // |