首页 > 设计 > 实用代码 > 正文

迷你网页便签,运用Js的Cookies技术

2020-01-27 13:43:47
字体:
来源:转载
供稿:网友

阿蚊少-迷你网页便签,运用Js的Cookies技术,可以保存便笺内容,程序针对火狐做有兼容性测试,因此火狐下也可正常运行。迷你便笺作者:阿蚊少 QQ:262826028,使用方法:直接调用本JS文件即可,部分参数设置如下: 
  var YhTop = 100//设置相对上边的距离 
  var YhRight = 0//设置相对右边距离 
  var Days = 365//设置cookie保存的天 
  var TitleFont = "宋体"//设置便签标题字体 
  var TitleColor = "FFFFFF"//设置标题文本颜色 
  var NoteWidth =180//设置便签宽度 
  var NoteHeight =300 //设置便签高度 

");document.write("
");document.write("");document.write("");document.write("
使用Cookies技术
");document.write("
");document.write("
");//获取全局对象 /*由于之前使用 document.all(ID)造成FF不能使用*/var NoteDiv = document.getElementById('NoteDiv')//最外围容器var NoteButton = document.getElementById('NoteButton')//按钮var NoteBox = document.getElementById('YhNote')//盒子var NoteTextArea = document.getElementById('NoteContent')//文本域//操作涵数 cookie操作function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值{ var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();}function getCookie(name)//取cookies函数 { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return null;}//显示便签function showBox(){var content = getCookie('NoteCokie')//读取Cookieif(content==null){content = ''}NoteTextArea.innerHTML = content//给文本域赋值NoteButton.style.display = 'none'//隐藏打开按钮NoteBox.style.display='block'//显示盒子}//隐藏便签function closeBox() {save()//关闭时自动保存NoteButton.style.display = 'block'//显打开按钮NoteBox.style.display='none'//隐藏}//保存涵数function save(){SetCookie('NoteCokie',NoteTextArea.innerHTML)}//清空涵数function clear1(){NoteTextArea.innerHTML=''save()}//定位便签function ResetNoteDiv(){ NoteDiv.style.top = parseInt(document.documentElement.scrollTop,10)+YhTop + "px";//如果后面不加 px 在FF下不能使用 }//重定位便签window.onresize = ResetNoteDivwindow.onscroll = ResetNoteDiv//当用户自行关闭浏览器时,为防止数据失丢,自动实现保存window.onunload = save//-->












































上一篇:网页标题随机显示名人名言JS代码

下一篇:inputSuggest在文本框输入字符时提示

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
学习交流
热门图片
猜你喜欢的新闻
猜你喜欢的关注

新闻热点

2020-01-20 20:02:27

疑难解答

图片精选

网友关注