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)文章
微信小程序中上傳圖片并進(jìn)行壓縮的實(shí)現(xiàn)代碼
這篇文章主要介紹了微信小程序中上傳圖片并進(jìn)行壓縮的實(shí)現(xiàn)代碼,文中提到了上傳圖片并進(jìn)行壓縮的屬性值,需要的朋友可以參考下2018-08-08
JavaScript實(shí)現(xiàn)PC端橫向輪播圖
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)PC端橫向輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
js實(shí)現(xiàn)文章文字大小字號(hào)功能完整實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)文章文字大小字號(hào)功能的實(shí)現(xiàn)方法,可根據(jù)用戶(hù)習(xí)慣調(diào)整顯示文字的大小.詳細(xì)講述了實(shí)現(xiàn)這一功能的完整步驟.是非常實(shí)用的技巧,需要的朋友可以參考下2014-11-11
學(xué)習(xí)JavaScript設(shè)計(jì)模式(接口)
這篇文章主要帶領(lǐng)大家學(xué)習(xí)JavaScript設(shè)計(jì)模式,其中重點(diǎn)介紹接口,舉例說(shuō)明什么是接口,對(duì)接口進(jìn)行詳細(xì)剖析,感興趣的小伙伴們可以參考一下2015-11-11
深入理解JavaScript系列(35):設(shè)計(jì)模式之迭代器模式詳解
這篇文章主要介紹了深入理解JavaScript系列(35):設(shè)計(jì)模式之迭代器模式詳解,迭代器模式(Iterator):提供一種方法順序一個(gè)聚合對(duì)象中各個(gè)元素,而又不暴露該對(duì)象內(nèi)部表示,需要的朋友可以參考下2015-03-03
js 限制數(shù)字 js限制輸入實(shí)現(xiàn)代碼
在工作中經(jīng)常會(huì)遇到j(luò)s限制輸入方面的要求,本文將詳細(xì)介紹其實(shí)現(xiàn)原理,需要的朋友可以參考下2012-12-12

