0

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?

gunr2171
  • 16,104
  • 25
  • 61
  • 88

2 Answers2

1

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>
Amin Jafari
  • 7,157
  • 2
  • 18
  • 43
0

Just use setTimeout.

setTimeout(function() {
    $('#subscribe').reveal();
},5000);

Modal will be called after 5 seconds.

superrafal
  • 516
  • 1
  • 3
  • 10