Hello I am trying to get the correct answer to a jquery question. I have looked on this site and saw some examples but all I have tried do not work. I have this jquery pop up box and I am trying to have the popup first load with a timer (this I have working). However, most importantly I would like to have the popup only appear once per session. by this I mean if someone visits the site twice or if they click the "x" to close the popup the cookies will prevent the popup from displaying. Bellow is my code. Can someone help?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<title>Cookies</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
}
.backdrop {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: #000;
opacity: .0;
filter: alpha(opacity=0);
z-index:50;
display:none;
}
.box {
position: absolute;
top: 20%;
left: 30%;
width: 500px;
height: 300px;
overflow-y: scroll;
background: #fff;
z-index: 51;
padding: 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 5px #444444;
-webkit-box-shadow: 0px 0px 5px #444444;
box-shadow: 0px 0px 5px #444444;
display: none;
}
.close {
float: right;
margin-right: 6px;
cursor: pointer;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
//This function open the box after 10 seconds.
setTimeout(function(){
$('.lightbox').ready(function(){
$('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
$('.box').animate({'opacity':'1.00'}, 300, 'linear');
$('.backdrop, .box').css('display', 'block')
});
},10000);
//This function closes the box
$('.close').click(function(){
$('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
$('.backdrop, .box').css('display', 'none')
});
});
$('.close').click(function(){
close_box();
});
$('.backdrop').click(function(){
close_box();
});
});
function close_box(){
$('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
$('.backdrop, .box').css('display', 'none')
if($.cookie("lightbox") != 'true') {
$(".box").hide().trigger('click');
$.cookie("lightbox", "true", { path: '/', expires: null });
}
});
}
</script>
</head>
<body>
<div class="backdrop"></div>
<div class="box"><div class="close">X</div>
Light box</div>
</body>
</body>
</html>