1

I have a code that allows the modal to delay. And, if the user click on either YES (which has an id="closemodal"), or NO (which has data-dismiss="modal") link, the modal will not show up again until the user leaves the page and then comes back to the same page.

<script type="text/javascript">
$(document).ready(function() {  
        setTimeout(function(){
         $('#myModal').modal('show');
        }, 10000);
        $('#closemodal').click(function() {
        $('#myModal').modal('hide') });
});
</script>

But, what I want is that the modal doesn't show back up at all after being shown once already to the user. I found this post. I have combined it with my code as shown below.

But, I can't seem to get this to work. Any help is appreciated.

<script type="text/javascript">
$(document).ready(function() {  
    if($.cookie('msg') != null && $.cookie('msg') != "")
    {
        $("div#myModal.modal, .modal-backdrop").hide();
    }
    else
    {
        setTimeout(function(){
        $('#myModal').modal('show');
        }, 10000);
        $.cookie('msg', 1 ); //moved this up and changed 'str' to 1
        $('#closemodal').click(function() {
        $('#myModal').modal('hide'); });
    }
});
</script>

Any help would be greatly appreciated.

UPDATED: Just in case this helps anyone. This is what I ended up with with the help of this post.

<script type="text/javascript">
if($.cookie('prepare') != 'seen'){
    $.cookie('prepare', 'seen', { expires: 365, path: '/' }); // Set it to last a year, for example.
    setTimeout(function(){
         $('#myModal').modal('show');
        }, 1000);
    $('#closemodal').click(function() // You are clicking the close button
    {
        $('#myModal').modal('hide'); // Now the pop up is hiden.
    });
    $('#myModal').click(function(e) 
        {
        $('#myModal').fadeOut(); 
    });
};
</script>
Community
  • 1
  • 1
Nate
  • 11
  • 1
  • 4

1 Answers1

-1

This is what I use at Duct Tape DANYOL

$(document).ready(function () {
    if (document.cookie.indexOf("shown=true")<0) {
        var show = function(){
                $('#myModal').modal('show');
        };

        $(window).load(function(){
            var timer = window.setTimeout(show,5000);
        });
    }
    document.cookie = "shown=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
});
Topher
  • 141
  • 1
  • 2
  • 9