쿠키 를 기록 하 는 JavaScript 코드 라 이브 러 리 cookieLibrary.js
8268 단어 cookie코드 라 이브 러 리
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
/**//* Function to correct for 2.x Mac date bug. Call this function to fix a date object prior to passing it to SetCookie. IMPORTANT: This function should only be called *once* for any given date object! See example at the end of this document. */
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) { // except on the Mac - ahead of its time
date.setTime(date.getTime() - skew);
}
}
/**//* Function to return the value of the cookie specified by "name". name - String object containing the cookie name. returns - String object containing the cookie value, or null if the cookie does not exist. */
function GetCookie (name) {
var temp = name + "=";
var tempLen = temp.length;
var cookieLen = document.cookie.length;
var i = 0;
while (i < cookieLen) {
var j = i + tempLen;
if (document.cookie.substring(i, j) == temp) {
return getCookieVal(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
/**//* Function to create or update a cookie. name - String object containing the cookie name. value - String object containing the cookie value. May contain any valid string characters. [expiresDate] - Date object containing the expiration data of the cookie. If omitted or null, expires the cookie at the end of the current session. [path] - String object indicating the path for which the cookie is valid. If omitted or null, uses the path of the calling document. [domain] - String object indicating the domain for which the cookie is valid. If omitted or null, uses the domain of the calling document. [secure] - Boolean (true/false) value indicating whether cookie transmission requires a secure channel (HTTPS). The first two parameters are required. The others, if supplied, must be passed in the order listed above. To omit an unused optional field, use null as a place holder. For example, to call SetCookie using name, value and path, you would code: SetCookie ("myCookieName", "myCookieValue", null, "/"); Note that trailing omitted parameters do not require a placeholder. To set a secure cookie for path "/myPath", that expires after the current session, you might code: SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true); */
function SetCookie (name,value,expiresDate,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expiresDate) ? "; expires=" + expiresDate.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
/**//* Function to delete a cookie. (Sets expiration date to start of epoch) name - String object containing the cookie name path - String object containing the path of the cookie to delete. This MUST be the same as the path used to create the cookie, or null/omitted if no path was specified when creating the cookie. domain - String object containing the domain of the cookie to delete. This MUST be the same as the domain used to create the cookie, or null/omitted if no domain was specified when creating the cookie. */
function DeleteCookie (name,path,domain) {
if (GetCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
// Calling examples: // var expdate = new Date (); // FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object! // expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now // SetCookie ("ccpath", "http://www.dupcit.com/articles/", expdate); // SetCookie ("ccname", "WebWoman", expdate); // SetCookie ("tempvar", "This is a temporary cookie."); // SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/"); // SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true); // SetCookie ("goner", "This cookie must die!"); // document.write (document.cookie + ""); // DeleteCookie ("goner"); // document.write (document.cookie + "
"); // document.write ("ccpath = " + GetCookie("ccpath") + "
"); // document.write ("ccname = " + GetCookie("ccname") + "
"); // document.write ("tempvar = " + GetCookie("tempvar") + "
");
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
서버에서 쿠키 만료 값 가져오기브라우저는 쿠키 만료를 처리하므로 쿠키의 만료 값을 서버에 전달하지 않습니다. 서버에서 쿠키의 만료 값을 얻으려면 일부 조정을 해야 합니다. 두 가지 방법이 있습니다. JSON 값으로 쿠키를 생성할 수 있습니다 다른...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.