Skip to content

Instantly share code, notes, and snippets.

@ViniciusAugusto
Last active November 5, 2015 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ViniciusAugusto/49d3b66f5b59c7e8eba3 to your computer and use it in GitHub Desktop.
Save ViniciusAugusto/49d3b66f5b59c7e8eba3 to your computer and use it in GitHub Desktop.
Popup com cookie
jQuery(document).ready(function() {;
if (getCookie('popup') == "") {
beginNewsletterForm();
}
});
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function beginNewsletterForm () {
jQuery.fancybox({
'width': '600px',
'height': '400px',
'padding': '0px',
'autoScale': true,
'transitionIn': 'fade',
'transitionOut': 'fade',
'showCloseButton': true,
'type': 'inline',
'href': '#newsletter-popup',
beforeClose:function(){
setCookie('popup', '1', '1');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment