There is a relationship between the two windows. Parent window parent.htmopen window son.htm
The child window can point to the parent window through window. opener. In this way, the object of the parent window can be accessed.
Advantage: convenient value. As long as window. opener points to the parent window, all objects can be accessed.
Not only can access the value, but also can access the parent window method. The value length is unlimited.
Disadvantage: there must be a relationship between the two windows. It is the window opened by window. open. Cross-Domain is not allowed.
Post.htm
<Input type = text name = maintext>
<Input type = button onclick = "too many open('read.htm')" value = "Open">
Read.htm
<Script language = "javascript">
// Window. open window.
// Use opener to point to the parent window.
Var parentText = too many opener.doc ument. all. maintext. value;
Alert (parentText );
</Script>
Use cookies.
Cookie is used by the browser to store a small amount of named data.
It is associated with a specific webpage or website.
Cookies are used to provide memory for browsers,
So that scripts and server programs can use the input data of another page on one page.
Advantage: it can be accessed from any webpage in the same source. The lifecycle can be set.
Disadvantage: The value length is limited.
Post.htm
<Input type = "text" name = "txt1">
<Input type = "button" onclick = "setCookie('baobao',document.all.txt 1. value)" 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.
* Instance: 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 x 24x60*60*1000 );
Document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();
Location. href = "Read.htm"; // receiving page.
}
</Script>
Read.htm
<Script language = "javascript">
Function getCookie (name)
{
/*
* --------------- GetCookie (name )-----------------
* GetCookie (name)
* Function: Get the variable name value.
* Parameter: name, String.
* Instance: 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>
URL
Pass through the URL to pass the value. Connect the information to be passed to the URL.
Advantage: The value is convenient. Cross-origin is supported.
Disadvantage: The value length is limited.
Post.htm
<Input type = "text" name = "username">
<Input type = "text" name = "sex">
<Input type = "button" onclick = "Post ()" value = "Post">
<Script language = "javascript">
Function Post ()
{
// Single value Read.htm? Username = baobao;
// What is the full value of 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 to obtain the URL string, Request ("AAA ")
* Parameter: key, String.
* Instance: alert (Request ["AAA"])
* --------------- Request.htm -----------------
*/
Var url = location. search;
Var Request = new Object ();
If (url. indexOf ("? ")! =-1)
{
Var str = url. substr (1) // remove? No.
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>