Skip to content

Instantly share code, notes, and snippets.

@shalakolee
Created April 25, 2017 23:17
Show Gist options
  • Save shalakolee/e75a5b20495dcb00a15d27904c4bd193 to your computer and use it in GitHub Desktop.
Save shalakolee/e75a5b20495dcb00a15d27904c4bd193 to your computer and use it in GitHub Desktop.
Exit popup with cookie
<script type="text/javascript">
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
//createCookie('onetimepopup','1',1);
function readCookie(name) {
var nameEQ = escape(name) + "=";
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, c.length);
if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
function closeOverAgePopup() {
$.fancybox.close();
createCookie('leavingPopup', '1', 3);
}
function closeleavingOferpopup() {
createCookie('leavingPopupcookie', '1', 30);
}
$(document).ready(function(){
$(".fancybox").fancybox({
'type': 'iframe',
'overlayShow' : true,
'closeBtn': false,
'width': 446,
'enableEscapeButton' : false,
'padding': 0,
'scrolling': 'no',
onClosed : function() {
closeleavingOferpopup();
},
helpers: {
overlay: { closeClick: false },
iframe: {scrolling: 'no'}
},
keys: {close: null}
});
if (readCookie('leavingPopup') != 1) {
$("#leavingPopupLink").click();
}
});
</script>
<a class="fancybox" id="leavingPopupLink" href="/popup.html" data-fancybox-type="iframe"></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment