写一个网站的告示页面,用JavaScript方式来写网页的cookie3有效时间。

window.onload = function(){

checkCookie();//加载事件,执行检查cookie。

}

//获取cookie方法

function getCookie(c_name)

{

if (document.cookie.length>0)

{

c_start=document.cookie.indexOf(c_name + "=")//1

if (c_start!=-1)

{

c_start=c_start + c_name.length+1 //5

c_end=document.cookie.indexOf(";",c_start)//4

if (c_end==-1) c_end=document.cookie.length

return (document.cookie.substring(c_start,c_end))

}

}

return ""

}

//设置cookie方法

function setCookie(c_name,value,expiredays)

{

var exdate=new Date()

exdate.setDate(exdate.getDate()+expiredays)

document.cookie=c_name+ "=" +escape(value)+

((expiredays==null) ? "" : ";expires="+exdate.toGMTString())

}

//检查cookie,用于判断是否记载larey弹窗插件。

function checkCookie()

{

var username=getCookie('username')

if (username==null || username==""){

//

setCookie('username','username',1)

//这是leary弹窗插件,如果需要用,就要引入插件文件

layer.open({

content:这是可以写html样式和链接


btn: '我知道了'

});

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 什么是 Cookie “cookie 是存储于访问者的计算机中的变量。每当同一台计算机通过浏览器请求某个页面时,就...
    恩德_b0c2阅读 450评论 0 3
  • 下面是我之前在W3School上学习JavaScript过程中做的的一些笔记,是关于JavaScript的基础知识...
    天遮不住我的眼阅读 371评论 0 3
  • 这两天做了一个小的offer项目,然后遇到了一些问题,稍微总结一下,感触最深的是cookie,因为之前只是简单的听...
    艾石溪阅读 256评论 0 0
  • 1.浏览器对象模型 (BOM) 使 JavaScript 有能力与浏览器“对话”。 2.Window 对象 所有浏...
    ancientear阅读 357评论 0 2
  • 方法一 对php.ini进行修改 file_uploads = on; //是否允许通过http上传文件的开关(默...
    SilverBullet007阅读 941评论 0 1