Skip to content

Instantly share code, notes, and snippets.

@namklabs
Created March 21, 2012 15:38
Show Gist options
  • Save namklabs/2148626 to your computer and use it in GitHub Desktop.
Save namklabs/2148626 to your computer and use it in GitHub Desktop.
JS Cookies with jQuery alerts on pageload
;
//cookie functions
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name){
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
$(function(){
$(".xcontinue").click(function(){ $(".alert").fadeOut(); });
$(".xclose").click(function(){ $(".alert").fadeOut(); setCookie("alert","true",1); });
alert_trig=getCookie('alert');
if (alert_trig!="true"){
if( $(".alert_jsform").length > 0 ){
var alert_timeout = setTimeout('$(".alert").fadeIn();',500);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment