landbryo
9/10/2018 - 5:59 PM

Super simple code to add a popup with a cookie created on closing.

Super simple code to add a popup with a cookie created on closing.

<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>