Last active
November 5, 2015 10:49
-
-
Save ViniciusAugusto/49d3b66f5b59c7e8eba3 to your computer and use it in GitHub Desktop.
Popup com cookie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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