Core Tip: This article lists three ways to get address bar parameters with JavaScript
This article lists three ways to get address bar parameters using javascript:
Method One:
<script type= "Text/javascript" >
<!--
String.prototype.getQuery = function (name) {
var reg = new RegExp ("(^&)" + name + "= ([^&]*) (&$)");
var r = this.substr (This.indexof ("\?") +1). Match (REG);
if (r!=null) return unescape (r[2]); return null;
}
var strhref = "WWW.CNLEI.ORG/INDEX.HTM?A=AAA&B=BBB&C=CCC";
Alert (Strhref.getquery ("a"));
Alert (Strhref.getquery ("B"));
Alert (Strhref.getquery ("C"));
-->
</script>
Method Two:
<script type= "Text/javascript" >
function Geturlpara (paraname) {
var surl = location.href;
var sreg = "(?: \ \?&) {1} "+paraname+" = ([^&]*)
var re=new RegExp (Sreg, "GI");
Re.exec (sURL);
return regexp.$1;
}
Application Example: test_para.html?a=11&b=22&c=33
Alert (Geturlpara ("a"));
Alert (Geturlpara ("B"));
</script>
Method Three:
<script type= "Text/javascript" >
<!--
function Request (strName) {
var strhref = "WWW.CNLEI.ORG/INDEX.HTM?A=AAA&B=BBB&C=CCC";
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 "";
}
Alert (Request ("a"));
Alert (Request ("B"));
Alert (Request ("C"));
-->
</script>