<html>
<head>
<meta charset="utf-8">
<title>Javascript cookie</title>
<script type="text/javascript">
function getCookie(c_name)
{
alert(document.cookie);
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
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
} 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());
} function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null)
{
document.cookie= name + "=" + cval + ";expires=" + exp.toGMTString();
}
} function checkCookie()
{
var username = getCookie('testJavascriptCookie');
if (username != null && username != "")
{
alert('Welcome again ' + username + '!');
}
else
{
username = prompt('Please enter your name:', "");
if (username != null && username != "")
{
setCookie('testJavascriptCookie', username, 365);
}
}
} </script>
</head> <body onLoad="checkCookie();">
</body>
</html>

js cookie 操作的更多相关文章

  1. js cookie 操作 封装

    pCookie.js (function(){ var PotatogCookie = {}; //设置cookie PotatogCookie.set = function(key, value, ...

  2. js cookie操作

    //写Cookie function writeCookie(name, value) { var expire = new Date(); expire.setFullYear(expire.get ...

  3. js简单操作Cookie

    贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...

  4. js中cookie操作

    js中操作Cookie的几种常用方法 * cookie中存在域的概念,使用path和domain区分: * 在同一域中的set和del可以操作同一名称的cookie,但不在同一域中的情况下,则set无 ...

  5. js 判断js函数、变量是否存在 JS保存和删除cookie操作,判断cookie是否存在的方法

    //是否存在指定函数 function isExitsFunction(funcName) {    try {        if (typeof(eval(funcName)) == " ...

  6. JS封装cookie操作函数实例(设置、读取、删除)

    本文实例讲述了JS封装cookie操作函数.分享给大家供大家参考,具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  7. js实用方法记录-简单cookie操作

    js实用方法记录-简单cookie操作 设置cookie:setCookie(名称,值,保存时间,保存域); 获取cookie:setCookie(名称); 移除cookie:setCookie(名称 ...

  8. Jquery和js实现cookie操作手机浮层广告;附加:js获取、添加、删除cookie

    1.jquery cookie包实现手机上的浮层广告 <span style="font-size:18px;">$(document).ready(function( ...

  9. nw.js的cookie操作

    在实战中,我遇到nw.js cookie一个奇怪的现象. 当我写入cookie(非httponly)后,关闭nw.js.然后再打开nw.js发现cookie没有写入成功.经过摸索,发现 nw.js的c ...

随机推荐

  1. IDEA | 创建启动SpringBoot项目命令

    clean package spring-boot:run -Dmaven.test.skip=true

  2. Python面向对象之单例模式

    单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某 一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就 能派上用场. 单例 ...

  3. 题解 BZOJ 1037 & Luogu P2592 [ZJOI2008]生日聚会

    BZOJ & Luogu 老师说是背包?并没看出来QAQ 设f[i][j][o][p]表示已经选了i个人,j个男生,男生比女生最多多o个,女生比男生最多多p个时的方案数 两种转移: <= ...

  4. Codeforces Round #562 (Div. 2) B. Pairs

    链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...

  5. Python网络编程中的服务器架构(负载均衡、单线程、多线程和同步、异步等)

    这篇文章主要介绍服务器架构. 网络服务需要面对两个挑战. 第一个问题是核心挑战,要编写出能够正确处理请求并构造合适响应的代码. 第二个挑战是如何将网络代码部署到随系统自动启动的Windows服务或者是 ...

  6. express转发请求

    express var express = require('express'); var axios = require('axios'); var qs = require('qs'); var ...

  7. Windows中将nginx添加到服务

    下载安装nginx http://nginx.org/en/download.html 下载后解压到C盘 C:\nginx-1.14.0 添加服务 需要借助"Windows Service ...

  8. LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 .NET 4.5 installed Visual Studio 2012 Release Preview

    Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' after ...

  9. (转)!注意:PreTranslateMessage弹出框出错

    dlg.DoModal()截住了界面消息,所以返回时原来的pMsg的内容已经更改了,消息,窗口句柄都不在是if以前的值了,而且窗口句柄应该是对话框里的子窗口的句柄,所以调用CFrameWnd::Pre ...

  10. SQL SEVER数据库重建索引的方法

    一.查询思路 1.想要判断数据库查询缓慢的问题,可以使用如下语句,可以列出查询语句的平均时间,总时间,所用的CPU时间等信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...