cookie & cookies
cookie & cookies
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description cookies
* @augments
* @example
*
*/
// const cookiesGenerator = (datas = [], debug = false) => {
// let result = ``;
// // do something...
// return result;
// };
// export default cookies;
// export {
// cookies,
// };
;(function (factory) {
var registeredInModuleLoader;
if (typeof define === 'function' && define.amd) {
define(factory);
registeredInModuleLoader = true;
}
if (typeof exports === 'object') {
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function decode (s) {
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
}
function init (converter) {
function api() {}
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return;
}
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
}
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
try {
var result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {
if (console.log) {
console.log("error =", e);
}
}
value = converter.write ?
converter.write(value, key) :
encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
key = encodeURIComponent(String(key))
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
.replace(/[\(\)]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}
return (document.cookie = key + '=' + value + stringifiedAttributes);
}
function get (key, json) {
if (typeof document === 'undefined') {
return;
}
var jar = {};
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var cookie = parts.slice(1).join('=');
if (!json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
var name = decode(parts[0]);
cookie = (converter.read || converter)(cookie, name) ||
decode(cookie);
if (json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
jar[name] = cookie;
if (key === name) {
break;
}
} catch (e) {}
}
return key ? jar[key] : jar;
}
api.set = set;
api.get = function (key) {
return get(key, false /* read as raw */);
};
api.getJSON = function (key) {
return get(key, true /* read as json */);
};
api.remove = function (key, attributes) {
set(key, '', extend(attributes, {
expires: -1
}));
};
api.defaults = {};
api.withConverter = init;
return api;
}
return init(function () {});
}));
function cookies() {
var D = new Date();
D.setDate(D.getDate() + 30);
document.cookie = "author=xgqfrms; website=www.xgqfrms.xyz; domain=xgqfrms.xyz; secure ;expire=" + D;
/*
// read cookie
var rc = document.cookie.substring(5);
if (rc != "www.xgqfrms.xyz") {
alert("cookie is empty!"+rc);
var D = new Date();
D.setDate(D.getDate()+30);
//write cookie
document.cookie="name=www.xgqfrms.xyz;domain=xgqfrms.xyz;HttpOnly;expire="+D;
}else{
alert("cookie is:"+rc);
}
*/
};
cookies();
view-source:https://www.xgqfrms.xyz/
cookie & cookies的更多相关文章
- 服务器获取浏览器发送请求中的cookies,选取自己需要的cookie
String cookieName = “userID”; // 设置自己需要的cookie名 Cookie cookies[] = request.getCookies(); // 获取请求中的所有 ...
- tomcat使用cookies缓存的时候中文报错解决办法 java.lang.IllegalArgumentException: Control character in cookie value or attribute.
报错出现 java.lang.IllegalArgumentException: Control character in cookie value or attribute. at org.apac ...
- Cookie的使用、Cookie详解、HTTP cookies 详解、获取cookie的方法、客户端获取Cookie、深入解析cookie
Cookie是指某些网站为了辨别用户身份.进行session跟踪而存储在用户本地终端上的数据(通常经过加密),比如说有些网站需要登录才能访问某个页面,在登录之前,你想抓取某个页面内容是不允许的.那么我 ...
- Spring cookie 实战
测试环境搭建 使用Springboot构建web server, 在测试方法中打印接收的cookie. @RestController @RequestMapping("/register/ ...
- Cookie和Session的总结
1.开篇 在之前学习这一段的时候我一直有点没弄清楚,其实对Session这块的理解还可以,但是Cookie感觉始终还是欠缺点火候.之后的很长一段时间都基本上很少用Cookie了,渐渐的也淡忘了这一块的 ...
- [JavaEE笔记]Cookie
引言 由于 Http 是一种无状态的协议,服务器单从网络连接上无从知道客户身份. 会话跟踪是 Web 程序中常用的技术,用来跟踪用户的整个会话.常用会话跟踪技术是 Cookie 与 Session. ...
- c++ builder TIdHttp 获取不到cookie
用c++ builder 的TIdHttp组件Get一个ASP.Net MVC服务器的一个页面,获取页面中Cookie信息,修改后Post到服务器上去. 在本地调试的时候可以获取到,部署到服务器上就获 ...
- java的会话管理:Cookie和Session
java的会话管理:Cookie和Session 1.什么是会话 此处的是指客户端(浏览器)和服务端之间的数据传输.例如用户登录,购物车等 会话管理就是管理浏览器客户端和服务端之间会话过程产生的会话数 ...
- Cookie和Session的那些事儿
Cookie和Session都是为了保持用户的访问状态,一方面为了方便业务实现,另一方面为了简化服务端的程序设计,提高访问性能.Cookie是客户端(也就是浏览器端)的技术,设置了Cookie之后,每 ...
随机推荐
- 最常用的~正则表达式-相关js函数知识简洁分享【新手推荐】
一.正则表达式的创建 JS正则的创建有两种方式: new RegExp() 和 直接字面量. //使用RegExp对象创建 varregObj =newRegExp("(^\s+)|(\s+ ...
- bzoj 2957: 楼房重建【线段树】
总之就是找前面所有点的斜率都严格小于这个点的这样的点的个数 不管是询问还是修改都非常线段树啊,而且相当眼熟是不是和hotel有点像啊,大概就是区间内记一个len一个max,分别是当前区间答案和区间最大 ...
- bzoj 1770: [Usaco2009 Nov]lights 燈【高斯消元+dfs】
参考:https://blog.csdn.net/qq_34564984/article/details/53843777 可能背了假的板子-- 对于每个灯建立方程:与它相邻的灯的开关次数的异或和为1 ...
- noip2016 小结(ac两题+学习总结)
NOIP2016考试小结 DAY 1 T1 题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业. 有一天, 这些玩具小人把小南的眼镜藏了起来. 小南发现玩具小人们围成了一个圈,它们有的面朝圈内, ...
- HTML <input>标签属性
- oozie timezone时区配置
cloudera oozie默认时区是UTC,在开发oozie任务时必须在期望执行的时间上减去8小时,很不习惯.记录下修改时区的配置操作. 1. cloudera oozie配置—>Oozie ...
- 解决WebSocket后台报错:The WebSocket session [0] has been closed and no method (apart from close()) may be called on a closed session
场景1: 在后台数据对前台页面进行数据实时推送下,后台采取定时查询数据后,推送给前台页面.在这个过程中,前台页面不停的刷新页面,session在不停的关闭和开启,推送数据时,会出现session连接已 ...
- ViewPager(4)用viewpager实现splash view
1,示例 2,代码 SplashMain.java import android.os.Bundle; import android.support.v4.app.Fragment; import a ...
- php 报错如下:Notice: Trying to get property of non-object
参考文档如下解决: https://stackoverflow.com/questions/5891911/trying-to-get-property-of-non-object-in 问题如下: ...
- Kafka~消费的有效期
消息的过期时间 我们在使用Kafka存储消息时,如果已经消费过了,再永久存储是一种资源的浪费,所有,kafka为我们提供了消息文件的过期策略,可以通过配置server.properies来实现# vi ...