I've successfully used this script to set a jquery cookie that shows site visitors a reveal modal but only once per day.
<script type="text/javascript">
$(document).ready(function(){
// if the cookie doesn't exist create it and show the modal
if ( ! $.cookie('hereToday') ) {
// create the cookie. Set it to expire in 1 day
$.cookie('hereToday', true, { expires: 1 });
//call the reveal modal
$('#subscribe').reveal();
}
});
</script>
How can I add a timeout function to the script that would add a few seconds delay before firing the modal?
you must use, setTimeout
function:
<script type="text/javascript">
$(document).ready(function(){
// if the cookie doesn't exist create it and show the modal
if ( ! $.cookie('hereToday') ) {
// create the cookie. Set it to expire in 1 day
$.cookie('hereToday', true, { expires: 1 });
//call the reveal modal
var delay=5000; //in ms, this would mean 5 seconds
setTimeout(function(){
$('#subscribe').reveal();
},delay);
}
});
</script>