In JavaScript, you can use the window.location.href property to get the full URL. This means we can pass parameters using GET mode, i.e., the form’s method="GET".
Below is a JavaScript function that retrieves values submitted via GET mode.
1
2
3
4
5
6
7
8
9
10
11
12
| function Request(strName) {
var strHref = window.document.location.href;
var intPos = strHref.indexOf("?");
var strRight = strHref.substr(intPos + 1);
var arrTmp = strRight.split("&");
for (var i = 0; i < arrTmp.length; i++) {
var arrTemp = arrTmp[i].split("=");
if (arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
}
return "";
}
|
Usage:
var id=Request("id");
document.write(id);