开发者

Show jquery dialog once per user

开发者 https://www.devze.com 2023-02-28 03:35 出处:网络
I use modal dialog on page open and I\'d like to show it once for each user. Here is the code,but it doesn\'t work

I use modal dialog on page open and I'd like to show it once for each user. Here is the code,but it doesn't work

<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
    $("#dialog").dialog({
        modal: true
    }); 
    $(function() {
        if ($.cookie('shownDialog') != 'true') {
            $('#dialog').dialog();
        }
        $.cookie('shownDialog', 'true', {expires: 7});
    });
    $("#close").click(function(event) {
        event.preventDefault();
   开发者_StackOverflow社区     $(this).closest(":ui-dialog").dialog("close");
    });
});
// ]]>
</script>

Can someone help me to fix code?


I'm guessing you're seeing the dialog always instead of once per user.

$(document).ready(function(){
     $("#dialog").dialog({
                modal: true
}); 

This part is going to show the dialog immediately, before ever reaching your check for display.

You should get rid of it and move your modal option into the if block instead:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
    $(function() {
          if ($.cookie('shownDialog') != 'true') {
              $("#dialog").dialog({
                    modal: true
               }); 
          }
          $.cookie('shownDialog', 'true', {expires: 7});
    });
    $("#close").click(function(event) {
      event.preventDefault();
      $(this).closest(":ui-dialog").dialog("close");
    });
});
// ]]>
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消