0

I have developed this code which is working well.

The problem is that it loads on every page even when I close it. Is there a way, maybe cookie based, to stay closed for a certain amount of time?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />

<script type="text/javascript">                                         
$(document).ready(function() {                         
 $("#ModalMessage").dialog({modal: true, autoOpen : true});  
});
</script>
Jason
  • 2,278
  • 2
  • 17
  • 25
Savito
  • 1

1 Answers1

0

Add this method to your HTML file.

var createCookie = function(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

Then, you can use something like this on Close dialog:

createCookie("closed", "1", 30);

On load your page:

$(document).ready(function() {                         
    if(getCookie("closed") != ""){
        //show my dialog box;
        $("#ModalMessage").dialog({modal: true, autoOpen : true}); 
    }
});

More about functions createCookie and getCookie here.

Pang
  • 9,564
  • 146
  • 81
  • 122
Eliasz Kubala
  • 3,836
  • 1
  • 23
  • 28