One: JavaScript static page value pass URL
Can pass the value of the URL. Connect the information you want to pass to the URL.
Post.htm
Copy Code code as follows:
<input type= "text" name= "username" >
<input type= "text" name= "Sex" >
<input type= "button" value= "Post" >
<script language= "JavaScript" >
function Post ()
{
Single value Read.htm?username=baobao;
Multi-value 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
Copy Code code as follows:
<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.jb51.net/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.jb51.net/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: Limited Value length
Second: JavaScript static page value Pass Cookie
A cookie is a browser that stores a small number of named data.
It is associated with a particular Web page or Web site.
Cookies are used to provide memory to the browser,
So that scripts and server programs can use the input data from another page in one page.
Post.htm
Copy Code code as follows:
<input type= "text" name= "Txt1" >
<input type= "button" value= "Post" >
<script language= "JavaScript" >
function Setcookie (name,value)
{
/*
*---------------Setcookie (name,value)-----------------
* Setcookie (Name,value)
* Function: Set the value of the variable name
* Parameter: Name, string; value, String.
* Example: Setcookie (' username ', ' Baobao ')
*---------------Setcookie (name,value)-----------------
*/
var days = 30; This cookie will be saved for 30 days
var exp = new Date ();
Exp.settime (Exp.gettime () + days*24*60*60*1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
Location.href = "read.htm"; Receive page.
}
</script>
Read.htm
Copy Code code as follows:
<script language= "JavaScript" >
function GetCookie (name)
{
/*
*---------------GetCookie (name)-----------------
* GetCookie (name)
* Function: Get the value of the variable name
* Parameter: Name, String.
* Example: Alert (GetCookie ("Baobao"));
*---------------GetCookie (name)-----------------
*/
var arr = Document.cookie.match (New RegExp ("(^|)" +name+ "= ([^;] *)(;|$)"));
if (arr!=null) return unescape (arr[2)); return null;
}
Alert (GetCookie ("Baobao"));
</script>
Advantages: can be accessed in any Web page within the same source. The lifetime can be set.
Disadvantage: The value length is limited.
Three: JavaScript static page value transmission of window.open article
There is a relationship between the two windows. Parent Window parent.htm Open child window son.htm
A child window can point to a parent window by Window.opener. This allows access to the object of the parent window.
Post.htm
Copy Code code as follows:
<input Type=text name=maintext>
<input Type=button value= "Open" >
Read.htm
<script language= "JavaScript" >
window.open the open window.
Use opener to point to the parent window.
var parenttext = Window.opener.document.all.maintext.value;
alert (Parenttext);
</script>
Advantage: The value is convenient. You can access all objects as long as the window.opener points to the parent window. You can access not only the values, but also the methods of the parent window. The value length is unlimited.
Disadvantages: Two windows have a relationship. is the window that is opened using window.open. Cannot cross domain.