JS控制COOKIE??
如何用JS控制COOKIE?给个列子
1.LOADING页读取COOKIE判断是否第一次打开首页,如果是就跳转到a.htm,a.htm过渡动画后跳转首页并写入COOKIE,如果不是就打开首页
2.按下清除COOKIE按钮后清除COOKIE
------解决方案--------------------給你一個測試用的例子,具體功能你自己搞定
<html>
<head>
<title>Cookies</title>
<script src="lib_cookie.js">
</script>
</head>
<body>
<h2>Set Cookie</h2>
<form name="setcooky">
Name: <input type="text" size="30" name="setcooky_name">
Value: <input type="text" size="30" name="setcooky_value">
<input type=button value="Set Cookie"
onclick="set_cookie(setcooky_name.value, setcooky_value.value);
alert('The cookie \'' + setcooky_name.value + '\', with value \'' + setcooky_value.value + '\', has been set.')"
</form>
<hr>
<h2>Get Cookie</h2>
<form name="getcooky">
<ul>
<li>Name: <input type="text" size="30" name="getcooky_name">
<input type=button value="Get Cookie Value"
onclick="getcooky_value.value=get_cookie(getcooky_name.value)">
Value: <input type="text" size="30" name="getcooky_value">
<br><br>
<li><input type=button value="Get document.cookie" onClick="alert(document.cookie)">
</ul>
</form>
<hr>
<h2>Delete Cookie</h2>
<form name="delcooky">
Name: <input type="text" size="30" name="delcooky_name">
<input type=button value="Delete Cookie"
onclick="del_cookie(delcooky_name.value);
alert('The cookie \'' + delcooky_name.value + '\' has been deleted.')"
</form>
</body>
</html>
<!-- ads begin -->
</noscript>
<!-- -->
</noscript>
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
// set expiration to 3 minutes
var expiration = new Date(); expiration.setTime(expiration.getTime() + 180000);
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length != 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) +
((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
"; path=/";
}
var xtpop;
function popWin() {
setCookie('Visits', 1, expiration);
xtpop = window.open("http://clickit.go2net.com/adclick?cid=197064&area=va.dir.edu&site=va&shape=exitpopup&keyword=exitpopup","xtpop","width=700,height=560,toolbar,scrollbars,menubar,resizable,top=100,left=100");
xtpop.blur();
setTimeout("xtpop.blur();",20);
setTimeout("xtpop.blur();",100);
self.focus();
}
var visitsCookie = getCookie('Visits');
if (visitsCookie == null) popWin();
// -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
browser = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 2 )) || ((navigator.appName == "Mic