JavaScript static page Value Pass URL Chapter

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.