/ Published in: JavaScript
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function Trim(strValue) {
return strValue.replace(/^\s+|\s+$/g, '');
}
function getCookie(key) {
var result = false;
if(document.cookie) {
var mycookieArray = document.cookie.split(';');
for(i=0; i<mycookieArray.length; i++) {
var mykeyValue = mycookieArray[i].split('=');
if(Trim(mykeyValue[0]) == key) result = mykeyValue[1];
}
}
return result;
}
function setCookie(key, value, hoursExpire) {
var ablauf = new Date();
var expireTime = ablauf.getTime() + (hoursExpire * 60 * 60 * 1000);
ablauf.setTime(expireTime);
document.cookie = key + "=" + value + "; expires=" + ablauf.toGMTString();
}
var mycookie = getCookie('meincookie');
if(!mycookie) {
// do whatever you want if the cookie is not set
setCookie('meincookie', 'true', 24);
} else {
// do whatever you want if the cookie is set
// mycookie contains the cookie value
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                