3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.util.Cookies"></div>/**
\r
15 * @class Ext.util.Cookies
\r
16 * Utility class for managing and interacting with cookies.
\r
19 Ext.util.Cookies = {
\r
20 <div id="method-Ext.util.Cookies-set"></div>/**
\r
21 * Create a cookie with the specified name and value. Additional settings
\r
22 * for the cookie may be optionally specified (for example: expiration,
\r
23 * access restriction, SSL).
\r
24 * @param {String} name The name of the cookie to set.
\r
25 * @param {Mixed} value The value to set for the cookie.
\r
26 * @param {Object} expires (Optional) Specify an expiration date the
\r
27 * cookie is to persist until. Note that the specified Date object will
\r
28 * be converted to Greenwich Mean Time (GMT).
\r
29 * @param {String} path (Optional) Setting a path on the cookie restricts
\r
30 * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>).
\r
31 * @param {String} domain (Optional) Setting a domain restricts access to
\r
32 * pages on a given domain (typically used to allow cookie access across
\r
33 * subdomains). For example, "extjs.com" will create a cookie that can be
\r
34 * accessed from any subdomain of extjs.com, including www.extjs.com,
\r
35 * support.extjs.com, etc.
\r
36 * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
\r
37 * should only be accessible via SSL on a page using the HTTPS protocol.
\r
38 * Defaults to <tt>false</tt>. Note that this will only work if the page
\r
39 * calling this code uses the HTTPS protocol, otherwise the cookie will be
\r
40 * created with default options.
\r
42 set : function(name, value){
\r
43 var argv = arguments;
\r
44 var argc = arguments.length;
\r
45 var expires = (argc > 2) ? argv[2] : null;
\r
46 var path = (argc > 3) ? argv[3] : '/';
\r
47 var domain = (argc > 4) ? argv[4] : null;
\r
48 var secure = (argc > 5) ? argv[5] : false;
\r
49 document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
\r
52 <div id="method-Ext.util.Cookies-get"></div>/**
\r
53 * Retrieves cookies that are accessible by the current page. If a cookie
\r
54 * does not exist, <code>get()</code> returns <tt>null</tt>. The following
\r
55 * example retrieves the cookie called "valid" and stores the String value
\r
56 * in the variable <tt>validStatus</tt>.
\r
58 * var validStatus = Ext.util.Cookies.get("valid");
\r
60 * @param {String} name The name of the cookie to get
\r
61 * @return {Mixed} Returns the cookie value for the specified name;
\r
62 * null if the cookie name does not exist.
\r
64 get : function(name){
\r
65 var arg = name + "=";
\r
66 var alen = arg.length;
\r
67 var clen = document.cookie.length;
\r
72 if(document.cookie.substring(i, j) == arg){
\r
73 return Ext.util.Cookies.getCookieVal(j);
\r
75 i = document.cookie.indexOf(" ", i) + 1;
\r
83 <div id="method-Ext.util.Cookies-clear"></div>/**
\r
84 * Removes a cookie with the provided name from the browser
\r
85 * if found by setting its expiration date to sometime in the past.
\r
86 * @param {String} name The name of the cookie to remove
\r
88 clear : function(name){
\r
89 if(Ext.util.Cookies.get(name)){
\r
90 document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
\r
96 getCookieVal : function(offset){
\r
97 var endstr = document.cookie.indexOf(";", offset);
\r
99 endstr = document.cookie.length;
\r
101 return unescape(document.cookie.substring(offset, endstr));
\r