Last active
September 10, 2018 18:06
-
-
Save landbryo/f87b7e9e4db25d97d86b83a2fa3466ae to your computer and use it in GitHub Desktop.
Super simple code to add a popup with a cookie created on closing.
This file contains hidden or 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
<h3>JS</h3> | |
<script> | |
function setCookie(cname, cvalue, exdays) { | |
var d = new Date(); | |
d.setTime(d.getTime()+(exdays*24*60*60*1000)); | |
var expires = "expires="+d.toGMTString(); | |
document.cookie = cname + "=" + cvalue + "; " + expires + '; path=/'; | |
} | |
function getCookie(cname) { | |
var name = cname + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0; i<ca.length; i++) { | |
var c = ca[i].trim(); | |
if (c.indexOf(name)==0) { | |
return c.substring(name.length,c.length); | |
} | |
} | |
return ""; | |
} | |
jQuery(window).load(function() { | |
if (getCookie("popped") == "") { | |
jQuery('#the-pop').fadeIn('slow'); | |
setCookie("popped", "viewed", 0.1); | |
} | |
}); | |
jQuery(window).load(function() { | |
jQuery('#the-pop .close').click(function() { | |
jQuery('#the-pop').fadeOut('slow'); | |
}); | |
}); | |
</script> | |
<h3>HTML</h3> | |
<div id="the-pop"> | |
<div class="close">Close [x]</div> | |
<div class="interior"> | |
<!-- pop content goes here --> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment