【问题标题】:How to set cookies in jquery modal dialog如何在 jquery 模态对话框中设置 cookie
【发布时间】:2012-08-07 19:22:03
【问题描述】:

我想将 cookie 添加到我的模态对话框中,但我不知道如何操作。我想添加 24 小时的 cookie,有人可以帮忙吗?这是我的模态对话框代码:

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript" href="/jquery/jquery.cookies.js"></script>

<script>
$(function() {
        // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
        if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') {

        $( "#dialog:ui-dialog" ).dialog( "disable" );
         $( ".selector" ).dialog({ hide: "slide" });
        $( "#dialog-modal" ).dialog({
            width:860,
            height: 420,
            modal: true,
            resizable:false,
            draggable:false
        });
        $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day
}
    });

    </script>



<link href="http://xxx.com/jquery/jquery.ui.all.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div id="dialog-modal" title="Like Us on Facebook">
    <div class="fb-like-box" data-href="http://www.facebook.com/xxx" data-width="820" data-height="335" data-show-faces="true" data-stream="false" data-header="false"></div> 
</div>

【问题讨论】:

标签: jquery jquery-ui cookies modal-dialog


【解决方案1】:

您的代码本身看起来不错,但是您还应该包含对 jQuery cookies pluginscript 引用,因为它不是 jQuery 的标准部分。

<script type="text/javascript" href="/scripts/jquery.cookies.js"></script>

您还需要在显示对话框后设置cookie:

if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') {
    // show dialog...
    $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day
}

【讨论】:

  • 我有一个问题,现在窗口不像模态对话框,但它在我页面的标题上方...我在上面的问题中编辑了代码!感谢您的帮助,罗里·麦克罗桑
猜你喜欢
  • 2011-08-19
  • 1970-01-01
  • 1970-01-01
  • 2011-12-12
  • 1970-01-01
  • 1970-01-01
  • 2014-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多