I wanna to get the query string of a page within a JavaScript block. for example:
The page has a URL like localhost:1234/Test/page1.aspx?ID=10
How can I get '10' with JavaScript?
window.location.search is the way to go.
Here's an example function:
function getQSVar( varname ) {
var query = window.location.search.substring( 1 );
var vars = query.split( "&" );
var len = vars.length;
for ( var i = 0; i < len; i++ ) {
var pair = vars[ i ].split( "=" );
if ( pair[ 0 ] == varname ) {
return pair[ 1 ];
}
}
return null;
}
Usage:
var IDValue = getQSVar( 'ID' ); // 10