URL Chapter
Can pass the value of the URL. Connect the information you want to pass to the URL.
Post.htm
<input type="text" name="username">
<input type="text" name="sex">
<input type="button" value="Post">
<script language="javascript" >
function Post()
{
//单个值 Read.htm?username=baobao;
//多全值 Read.htm?username=baobao&sex=male;
url = "Read.htm?username="+escape(document.all.username.value);
url += "&sex=" + escape(document.all.sex.value);
location.href=url;
}
</script>
Read.htm
<script language= "JavaScript" >
/*
*---------------read.htm-----------------
* Request[key]
* Function: Implement ASP's Get URL string, Request ("AAA")
* Parameter: Key, String.
* Example: Alert (request["AAA"])
*---------------request.htm-----------------
*/
var Url=location.search;
var Request = new Object ();
if (Url.indexof ("?")! =-1)
{
var str = URL.SUBSTR (1)//Remove number
STRs = Str.split ("&");
for (Var i=0;i<strs.length;i++)
{
Request[strs[i].split ("=") [0]]=unescape (strs[i].split ("=") [1]);
}
}
Alert (request["username"])
Alert (request["Sex"])
</script><script language= "JavaScript" >
<!--
function Request (strName)
{
var strhref = "www.abc.com/index.htm?a=1&b=1&c= test test";
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>
<script>
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 str = "www.abc.com/index.htm?a=1&b=1&c= test test";
Alert (Str.getquery ("a"));
Alert (Str.getquery ("B"));
Alert (Str.getquery ("C"));
</script>
Advantages: Easy to value. can cross domain.
Disadvantage: The value length is limited.