<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if ( (name + "=" + escape(value)).length <= 4000){
document.cookie = curCookie
}
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function savecookie(){
var cont=document.getElementById("te").value;
if(cont){
var data=new Date();
//data.setTime(data.getTime() + 1*24*3600*1000*1000); //对应天,小时,秒,自己换算设置
data.setTime(data.getTime() + 10000); //对应天,小时,秒,自己换算设置
setCookie("cont",cont,data);
}
}
window.onload=function(){
var cont=getCookie("cont");
if(cont) document.getElementById("te").value=cont;
}
</script>
</head>
<body>
<div >
<input type=area id="te" ><input type=button value="保存进cookie" id=cook onclick=savecookie() />
</div>
</body>
</html>
前端临时保存编辑的草稿文件
最新推荐文章于 2023-07-31 12:01:08 发布