Javascript Cookie操作パッケージの操作関数
3307 ワード
この美味しい「クッキー」はどのサイトにも欠かせないものです.「Cookie小怪獣の歓心を買い、クッキーを作ってみましょう.
if(typeof jscript='undefined')
jscript=function(){}
)
jscript.storge=function(){}
jscript.storge.set Cookie=function(inName,inValue,inExpiry){
if(typeof inExpiry="Date")
inExpiry=inExpiry.toGMT String()
)
document.co okie=inName+“=”+escape(inValue)+“;expires=”+inExpiry;
)//End set Cookie()
jscript.storge.get Cookie=function(inName){
var doc Cookies=document.co okie;
var cIndex=docCookies.indexOf(inName+「=」)
if(cIndex==-1){
return null
)
cIndex=docCookies.indexOf(=)、cIndex+1
var endStr=docCookies.indexOf(";",cIndex);
if(endStr==-1){
endStr=docCookies.length;
)
return unescape(docCookies.substring(cIndex,endStr);
)//End get Cookie()
jscript.storge.deleteCookie=function(inName){
if(this.get Cookie(inName){
this.set Cookie(inName,null,Thu,01-Jan-1970:00:01 GMT);
)
)//End deleteCookie()
set Cookie()-Set the cookie「chapter=HodgePodge」
get Cookie()-Get the cookie"chapter"
deleteCookie()-Delete the cookie"chapter"
/**
* jscript.storage package
* This package contains functions for doing client-side storage, including
* cookie functions.
*/
if (typeof jscript == 'undefined') {
jscript = function() { }
}
jscript.storage = function() { }
/**
* Sets a cookie.
*( Cookie)
* @param inName The name of the cookie to set.
* @param inValue The value of the cookie.
* @param inExpiry A Date object representing the expiration date of the
* cookie.
*/
jscript.storage.setCookie = function(inName, inValue, inExpiry) {
if (typeof inExpiry == "Date") {
inExpiry = inExpiry.toGMTString();
}
document.cookie = inName + "=" + escape(inValue) + "; expires=" + inExpiry;
} // End setCookie().
/**
* Gets thbe value of a specified cookie. Returns null if cookie isn't found.
*( Cookie )
* @param inName The name of the cookie to get the value of.
*/
jscript.storage.getCookie = function(inName) {
var docCookies = document.cookie;
var cIndex = docCookies.indexOf(inName + "=");
if (cIndex == -1) {
return null;
}
cIndex = docCookies.indexOf("=", cIndex) + 1;
var endStr = docCookies.indexOf(";", cIndex);
if (endStr == -1) {
endStr = docCookies.length;
}
return unescape(docCookies.substring(cIndex, endStr));
} // End getCookie().
/**
* Deletes a cookie.( Cookie)
*/
jscript.storage.deleteCookie = function(inName) {
if (this.getCookie(inName)) {
this.setCookie(inName, null, "Thu, 01-Jan-1970 00:00:01 GMT");
}
} // End deleteCookie().
クリックしてみますif(typeof jscript='undefined')
jscript=function(){}
)
jscript.storge=function(){}
jscript.storge.set Cookie=function(inName,inValue,inExpiry){
if(typeof inExpiry="Date")
inExpiry=inExpiry.toGMT String()
)
document.co okie=inName+“=”+escape(inValue)+“;expires=”+inExpiry;
)//End set Cookie()
jscript.storge.get Cookie=function(inName){
var doc Cookies=document.co okie;
var cIndex=docCookies.indexOf(inName+「=」)
if(cIndex==-1){
return null
)
cIndex=docCookies.indexOf(=)、cIndex+1
var endStr=docCookies.indexOf(";",cIndex);
if(endStr==-1){
endStr=docCookies.length;
)
return unescape(docCookies.substring(cIndex,endStr);
)//End get Cookie()
jscript.storge.deleteCookie=function(inName){
if(this.get Cookie(inName){
this.set Cookie(inName,null,Thu,01-Jan-1970:00:01 GMT);
)
)//End deleteCookie()
set Cookie()-Set the cookie「chapter=HodgePodge」
get Cookie()-Get the cookie"chapter"
deleteCookie()-Delete the cookie"chapter"