<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<script type="text/javascript">
//检测cookie
function getcookie(myname) {
if (document.cookie.length > 0) {
var start = document.cookie.indexOf(myname + "=");
if (start != -1) {
start = start + myname.length + 1;
var end =document.cookie.indexOf(";", start);
if (end == -1) {
end = document.cookie.length;
}
return unescape(document.cookie.substring(start, end));
}
}
return ""
}
//创建cookie
function setcookie(myname, value, expireday) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expireday);
document.cookie = myname + "=" + escape(value) + ((expireday == null) ? "" : ";expires=" + exdate.toGMTString())
}
function checkcookie() {
username = getcookie('username')
if (username != null && username != "") {
alert('Welcome again ' + username + '!')
} else {
username = prompt('Please enter your name:', "")
if (username != null && username != "") {
setcookie('username', username, 365)
}
}
}
</script>
<body onload="checkcookie()"></body>
</html>
柠檬酸钠
相关分类