Write the content to the cookie on one page, and obtain and display the content on the other page in the page (either in safari or firefox, but not in chrome, I don't know why .)
Page 1: click the button to write the form content to the cookie,
[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> setCookie </title>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> test2 </title>
<Script type = "text/javascript">
// Write cookie
Function writeCookie (name, value, hours ){
Var expire = "";
If (hours! = Null ){
Expire = new Date (). getTime () + hours * 3600000 );
Expire = "; expires =" + expire. toGMTString ();
}
Document. cookie = name + "=" + escape (value) + expire;
}
// Obtain the cookie
Function getCookie (Name)
{
Var search = Name + "= ";
If (document. cookie. length> 0)
{
Offset = document. cookie. indexOf (search)
If (offset! =-1)
{
Offset + = search. length
End = document. cookie. indexOf (";", offset)
If (end =-1) end = document. cookie. length
Return unescape (document. cookie. substring (offset, end ))
}
Else return "";
}
}
// Click the image to obtain the cookie.
Function getName (){
Var button = document. getElementById ("button ");
Var inhtml = document. getElementById ("inhtml ");
Button. onclick = function (){
Var name = getCookie ("username ");
Inhtml. innerHTML = name;
}
}
// Click Submit to write the cookie
Function add (){
Var connect = document. getElementById ("connect ");
Alert (connect. value );
WriteCookie ("username", connect. value, 24 );
}
</Script>
</Head>
<Body onload = "getName ();">
</Body>
<Form onsubmit = "add ();">
<Input type = "text" id = "connect"/>
<Input type = "submit" value = "submit"/>
</Form>
<Span id = "inhtml"> </span>
</Head>
<Body>
</Body>
</Html>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> setCookie </title>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> test2 </title>
<Script type = "text/javascript">
// Write cookie
Function writeCookie (name, value, hours ){
Var expire = "";
If (hours! = Null ){
Expire = new Date (). getTime () + hours * 3600000 );
Expire = "; expires =" + expire. toGMTString ();
}
Document. cookie = name + "=" + escape (value) + expire;
}
// Obtain the cookie
Function getCookie (Name)
{
Var search = Name + "= ";
If (document. cookie. length> 0)
{
Offset = document. cookie. indexOf (search)
If (offset! =-1)
{
Offset + = search. length
End = document. cookie. indexOf (";", offset)
If (end =-1) end = document. cookie. length
Return unescape (document. cookie. substring (offset, end ))
}
Else return "";
}
}
// Click the image to obtain the cookie.
Function getName (){
Var button = document. getElementById ("button ");
Var inhtml = document. getElementById ("inhtml ");
Button. onclick = function (){
Var name = getCookie ("username ");
Inhtml. innerHTML = name;
}
}
// Click Submit to write the cookie
Function add (){
Var connect = document. getElementById ("connect ");
Alert (connect. value );
WriteCookie ("username", connect. value, 24 );
}
</Script>
</Head>
<Body onload = "getName ();">
</Body>
<Form onsubmit = "add ();">
<Input type = "text" id = "connect"/>
<Input type = "submit" value = "submit"/>
</Form>
<Span id = "inhtml"> </span>
</Head>
<Body>
</Body>
</Html>
Click the image on the second page to display the cookie;
[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> cookietest3 </title>
<Script type = "text/javascript">
// Obtain the cookie
Function getCookie (Name)
{
Var search = Name + "= ";
If (document. cookie. length> 0)
{
Offset = document. cookie. indexOf (search)
If (offset! =-1)
{
Offset + = search. length
End = document. cookie. indexOf (";", offset)
If (end =-1) end = document. cookie. length
Return unescape (document. cookie. substring (offset, end ))
}
Else return "";
}
}
// Click the image to obtain the cookie.
Function getName (){
Var button = document. getElementById ("button ");
Var inhtml = document. getElementById ("inhtml ");
Button. onclick = function (){
Var name = getCookie ("username ");
Inhtml. innerHTML = name;
}
}
</Script>
</Head>
<Body onload = "getName ();">
<Span id = "inhtml"> </span>
</Body>
</Html>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> cookietest3 </title>
<Script type = "text/javascript">
// Obtain the cookie
Function getCookie (Name)
{
Var search = Name + "= ";
If (document. cookie. length> 0)
{
Offset = document. cookie. indexOf (search)
If (offset! =-1)
{
Offset + = search. length
End = document. cookie. indexOf (";", offset)
If (end =-1) end = document. cookie. length
Return unescape (document. cookie. substring (offset, end ))
}
Else return "";
}
}
// Click the image to obtain the cookie.
Function getName (){
Var button = document. getElementById ("button ");
Var inhtml = document. getElementById ("inhtml ");
Button. onclick = function (){
Var name = getCookie ("username ");
Inhtml. innerHTML = name;
}
}
</Script>
</Head>
<Body onload = "getName ();">
<Span id = "inhtml"> </span>
</Body>
</Html>