JavaScript Cookie 直接瀏覽網(wǎng)站分網(wǎng)址
更新時(shí)間:2009年12月08日 01:17:03 作者:
JavaScript Cookie 直接瀏覽網(wǎng)站分網(wǎng)址
httml代碼:
<!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">記住我的選擇
</form>
</body>
</html>
JS代碼:
<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.163.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>
復(fù)制代碼 代碼如下:
<!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">記住我的選擇
</form>
</body>
</html>
JS代碼:
復(fù)制代碼 代碼如下:
<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.163.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>
您可能感興趣的文章:
- javascript實(shí)現(xiàn)點(diǎn)擊單選按鈕鏈接轉(zhuǎn)向?qū)?yīng)網(wǎng)址的方法
- JavaScript給url網(wǎng)址進(jìn)行encode編碼的方法
- javascript學(xué)習(xí)網(wǎng)址備忘
- JavaScript獲取URL匯總
- JavaScript獲取Url里的參數(shù)
- 在JavaScript中獲取請(qǐng)求的URL參數(shù)[正則]
- javascript 獲取url參數(shù)和script標(biāo)簽中獲取url參數(shù)函數(shù)代碼
- Javascript 獲取鏈接(url)參數(shù)的方法
- javascript[js]獲取url參數(shù)的代碼
- JavaScript實(shí)現(xiàn)簡(jiǎn)單獲取當(dāng)前網(wǎng)頁(yè)網(wǎng)址的方法
相關(guān)文章
基于JavaScript代碼實(shí)現(xiàn)自動(dòng)生成表格
本文給大家分享一段js代碼實(shí)現(xiàn)輸入表格行數(shù)、列數(shù)自動(dòng)生成表格源代碼,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-06-06js實(shí)現(xiàn)不重復(fù)導(dǎo)入的方法
這篇文章主要介紹了js實(shí)現(xiàn)不重復(fù)導(dǎo)入的方法,實(shí)例分析了JavaScript基于文件與字符串判斷操作實(shí)現(xiàn)JS文件不重復(fù)導(dǎo)入的相關(guān)技巧,需要的朋友可以參考下2016-03-03無(wú)constructor的class類還能new嗎問(wèn)題解析
這篇文章主要為大家介紹了無(wú)constructor的class類是否還能new的問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03el-date-picker與el-time-picker的時(shí)間格式設(shè)置代碼
這篇文章主要介紹了el-date-picker與el-time-picker的時(shí)間格式設(shè)置代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-11-11Nautil 中使用雙向數(shù)據(jù)綁定的實(shí)現(xiàn)
這篇文章主要介紹了Nautil 中使用雙向數(shù)據(jù)綁定的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10