Httml code:
Copy to ClipboardReference: [www.bkjia.com] <! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Untitled Document </title>
</Head>
<Body>
<A href = "javascript: setHome ('dizhi1')"> Website1 </a>
<A href = "javascript: setHome ('dizhi2')"> Website2 </a>
<A href = "javascript: setHome ('dizhi3')"> Website3 </a>
<A href = "javascript: setHome ('dizhi4')"> Website4 </a>
<Form name = "homeform" method = "post">
<Input type = "checkbox" name = "setgo" value = "1"> remember my choice
</Form>
</Body>
</Html>
JS Code:
Copy to ClipboardReference: [www.bkjia.com] <script language = "JavaScript" type = "text/javascript">
<! --
Function getCookie (name ){
If (document. cookie. length> 0 ){
Start = document. cookie. indexOf (name + "= ");
If (start! =-1 ){
Start = start + name. length + 1;
End = document. cookie. indexOf (";", start );
If (end =-1 ){
End = document. cookie. length;
}
Return decodeURI (document. cookie. substring (start, end ));
}
}
Return "";
}
Function setCookie (name, value, expires, path, domain, secure ){
Var curcookie = name + "=" + encodeURI (value)
+ (Expires )? "; Expires =" + expires. toGMTString ():"")
+ (Path )? "; Path =" + path :"")
+ (Domain )? "; Domain =" + domain :"")
+ (Secure )? "; Secure ":"");
Document. cookie = curcookie;
}
Function goHome (myhome ){
If (myhome ){
Switch (myhome ){
Case "dizhi1 ":
Window. location = "http://www.qq.com ";
Break;
Case "dizhi2 ":
Window. location = "http://zghlx.cnblogs.com ";
Break;
Case "dizhi3 ":
Window. location = "http://www.sina.com.cn ";
Break;
Case "dizhi4 ":
Window. location = http://www.bkjia.com;
Break;
}
}
}
Function setHome (myhome ){
Var today = new Date ();
Var expires = new Date ();
Expires. setTime (today. getTime () + 365*24*60*60*1000 );
If (document. homeform. setgo. checked ){
SetCookie ("home", myhome, expires );
}
GoHome (myhome );
}
Window. onload = function (){
Var pHome = getCookie ("home ");
GoHome (pHome );
}
-->
</Script>
Source: http://www.cnblogs.com/zghlx/