Static Page value transfer (trilogy)

Source: Internet
Author: User
Tags setcookie

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>

Related Article

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.