Cookie Lightbox
by wrxsti85
HTML
<script src="http://diy-code.com/lightbox/jquery.lightbox_me.js"></script>
<div id="LB">This is a test lightbox...<br />
<button class="close">ENTER</button>
</div>
<div id="container">
<div id="header">Header</div>
<div id="nav">Navigation</div>
<div id="content">Content</div>
<div id="footer">Footer</div>
</div>
CSS
#LB {
display:none;
background: #fff;
border: solid 1px #000;
padding: 30px;
}
#container {
width: 500px;
background: #e5e5e5;
border: solid 1px #000;
margin-left: auto;
margin-right: auto;
padding: 10px;
}
#header {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
background: #fff;
border: solid 1px #000;
width: 400px;
height: 100px;
padding: 10px;
}
#nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
background: #fff;
border: solid 1px #000;
width: 400px;
height: 10px;
padding: 10px;
}
#content {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
background: #fff;
border: solid 1px #000;
width: 400px;
height: 250px;
padding: 10px;
}
#footer {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
background: #fff;
border: solid 1px #000;
width: 400px;
height: 20px;
padding: 10px;
}
JavaScript
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function checkCookie() {
var status = getCookie("status");
if (status != null && status != "") {} else {
$('#LB').lightbox_me();
setCookie("status", "1", 365);
if (status != null && status != "") {}
}
}
$(function() {
checkCookie();
});