代码如下:function ClearCookie() { var expires = new Date(); expires.setTime(expires.getTime() - 1000); //当前时间减去一秒,相当于立即过期(可以增减) document.cookie = "appCode=222;path=/;expires=" + expires.toGMTString() + ""; //expires是对应过期时间的设置,不设这个值,cookie默认在关闭浏览器时失效 document.cookie = "roleID=333;path=/;expires=" + expires.toGMTString() + ""; document.cookie = "parentMen...
写入cookie实例! 代码如下:var u = "value=123"; document.cookie = u; 读取cookie实例,读取value的值! 代码如下:var c_name="value"; // 变量名 if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "=") if (c_start != -1) { c_start = c_start + c_name.length + 1 c_end = document.cookie.indexOf(";", c_start) if (c_end == -1) c_end = document.cookie.length // document.write(docume...
代码如下:function setCookie(name,value,time){ var oDate = new Date(); oDate.setDate(oDate.getDate()+time); document.cookie = name+"="+value+";expires="+oDate; } function getCookie(name){ var arr = document.cookie.split("; "); for(var i=0; i<arr.length; i++){ var arr2 = arr[i].split("="); if(arr2[0] == name){ return arr2[1]; } } return ""; } function removeCookie(name){ setCookie(name,"",0) }
代码如下:Cookie = { setCookie: function (name, val) { var exp = new Date(); exp.setDate(exp.getDate() + 600 * 1000); document.cookie = name + "=" + escape(val) + ";expires=" + exp.toGMTString(); }, DelCookie: function (name) { document.cookie = name + "=;expires=" + (new Date(0)).toGMTString(); }, getCookie: function (name) { var cookieArray = document.c...
前言 在开发过程中,因为之前有接触过Discuz,就直接拿其common.js里面的getcookie和setcookie方法来使用,做到后面在使用IE来测试的时候,发现这两个方法子啊IE下不起作用,就请教同事,这样就有了jquery.cookie.js文件的由来,里面的代码很少,我贴在下面,方便以后使用和研究吧。 源码 代码如下:/** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * ht...
为了说清楚这个问题,必须从头说起。 首先从后台配置一个参数,放到一个字段里,该字段叫做keywords,这个参数的值叫做efmis://|efmfj|username|2200|0||2014|http://10.20.1.54:7001/cssServerportal222012/|||||02,姑且不去管这个值有什么含义,相信很多人都遇到过比这个更复杂的字符串。后台配置以后,前台可以这么来显示:${tag_bean.keywords},可以肯定,无论后台配置成什么,前台一定会原定不变的显示出来,第一个问题出现...
使用JQuery操作cookie时 发生取的值不正确的问题: 结果发现cookie有四个不同的属性: 名称,内容,域,路径 代码如下:$.cookie(the_cookie); // 读取 cookie $.cookie(the_cookie, the_value); // 存储 cookie $.cookie(the_cookie, the_value, { expires: 7 }); // 存储一个带7天期限的 cookie $.cookie(the_cookie, , { expires: -1 }); // 删除 cookie 使用: $.cookie("currentMenuID", menuID); 时 未指定域和路径。 所有当...
今天遇到一个问题,在使用cookie.js时,只有在jquery.js文件后加载整体才有效 有效加载顺序 代码如下:<head> <script type="text/javascript" src="./Scripts/scripts/jquery.1.3.2.js"></script> <script type="text/javascript" src="./Scripts/jquery.cookie.js"></script> </head>
核心代码: 代码如下:var cookie={ setCookie:function (name, value, iDay) { var oDate = new Date(); oDate.setDate(oDate.getDate()+iDay); document.cookie = name+=+value+;expires=+oDate; }, getCookie:function (name) { var arr = document.cookie.split(; ); for (var i = arr.length - 1; i >= 0; i--) { var arr2 = arr[i].split(=); if(arr2[0]===name){ return arr2[1]; } } return ; }, removeCookie:function (n...
[javascript] 代码如下:/** *pro_id: 产品id *brand_name : 品牌 *pro_name : 产品id *price : 价格 * catalog : 机型 * img : 图片 *file_name : 文件名 */ var addHistory=function(pro_id,brand_name,pro_name,price,catalog,img,file_name){ stringCookie=getCookie('history'); var stringHistory=""!=stringCookie?stringCookie:"{history:[]}"; var json=new JSON(stringHistory); var pro_ids = ...
代码如下://JS操作cookies方法! //写cookies function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } //读取cookies function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); el...
只出现一次的提示信息var alertmessage="Welcome to 脚本之家\n 这个提示信息只会出现一次哟!刷新一下页面试试?肯定没有提示了~" var once_per_session=1 function get_cookie(Name) {var search = Name + "="var returnvalue = "";if (document.cookie.length > 0) {offset = document.cookie.indexOf(search)if (offset != -1) { // if cookie existsoffset += search.lengthend = document.cookie.indexOf(";", offset);if (e...
P3PP3P是一種被稱為個人隱私安全平臺項目(the Platform for Privary Preferences)的標準,能夠保護在線隱私權,使Internet衝浪者可以選擇在瀏覽網頁時,是否被第三方收集並利用自己的個人信息。如果一個站點不遵守P3P標準的話,那麼有關它的Cookies將被自動拒絕,並且P3P還能夠自動識破多種Cookies的嵌入方式。P3P是由全球資訊聯盟網所開發的。 例子當頁面存在iframe時,想要獲取iframe框架裏面的cookie,就要在iframe相應的動態...
用JavaScript创建一个欢迎cookie 软件代码编辑器,我用的是editplus;当然还有浏览器。步骤 先在编辑器里写入代码:运行代码,并写入自己的名字:得到欢迎cookie.
代码如下:function getCookie(name) { var offset,cookieValue; var search=name+"="; if(document.cookie.length>0) { offset=document.cookie.indexOf(search); if(offset!=-1) { offset += search.length; end = document.cookie.indexOf(";", offset); if (end == -1) end = do...