帮助为JQuery UI模式对话框设置Cookie

时间:2011-05-06 14:57:54

标签: jquery jquery-ui cookies modal-dialog

我们拥有一个网上银行网站,登录后,我创建了一个模式对话框进行显示。

我们现在想要采用基于cookie的方法,因此只能看一次。我完全迷失了如何做到这一点。我有代码,如果有人可以提供帮助,我真的很感激。我需要完全如何编码。我不是很熟练的html / javascript - 我很幸运能够很幸运地实现这一点。但现在我无法让cookie部分正常工作!感谢任何能够帮助我的人。

    <body onLoad="loadPage();" onUnload="unloadPage();">
<script>
    $(function() {
        // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
        $( "#dialog:ui-dialog" ).dialog( "destroy" );

        $( "#dialog-modal" ).dialog({
            height: 475,
            width: 550,
            position: 'top',
            modal: true,
            buttons:{ "Close": function() { $(this).dialog("close"); } },
            draggable: false,
            resizable: false
        });

    });

    </script>

<div class="optinpopup">
<div id="dialog-modal" title="Alert">
    <br><b>IMPORTANT MESSAGE FOR ATM/DEBIT CARD HOLDERS</b>
    <br><br>
        Federal Regulations recently changed, which means we are required to get your permission to consider paying overdrafts on your everyday debit transactions.
        <br><br>
        Please <a href="www.websitehere.com" style="text-decoration: none; " target="_blank"><b>click here</b></a> to find out important information regarding overdraft charges and debit card transactions.
        <br></div></div>

2 个答案:

答案 0 :(得分:2)

抓住jQuery cookie plugin并更改您的代码:

$(function() {
    // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
    $( "#dialog:ui-dialog" ).dialog( "destroy" );

    if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') {
        $( "#dialog-modal" ).dialog({
            height: 475,
            width: 550,
            position: 'top',
            modal: true,
            buttons:{ "Close": function() { $(this).dialog("close"); $.cookie('showDialog', 'false', { expires: 3650 });  } },
            draggable: false,
            resizable: false
        });
    }    
});

答案 1 :(得分:0)

$( '.home_page_popup' ).dialog({ 
    autoOpen: false,
    closeText: "",
    modal: true,
    resizable: false,
    icon: "ui-icon-heart",
    classes: {
        "ui-dialog": "home_page_popup_dialog"
    },
    width: pop_up_width
});

$(".home_page_popup").on("click",".popup_close",function() {

    if ($.cookie('subscribe_popup_status') == null) {
        $.cookie('subscribe_popup_status', 'shown',{ expires: popup_duration } );
    }

    $( '.home_page_popup' ).dialog('close');

});