帮助为JQuery UI模式对话框设置Cookie
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了帮助为JQuery UI模式对话框设置Cookie相关的知识,希望对你有一定的参考价值。
我们主持一个网上银行网站,登录后,我创建了一个模式对话框进行显示。
我们现在想要采用基于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>
答案
抓住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
});
}
});
另一答案
$( '.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');
});
以上是关于帮助为JQuery UI模式对话框设置Cookie的主要内容,如果未能解决你的问题,请参考以下文章