[英]jQuery Dialog Popup Cookie
我需要此彈出窗口僅對每個訪問者顯示一次。 當用戶單擊關閉按鈕時,Cookie應該觸發並將彈出窗口設置為30天不顯示。 我曾嘗試自己安裝cookie,但由於對JavaScript的了解有限而無濟於事。 我已經在此處閱讀了與此相關的幾篇文章,但它們對我沒有幫助。
JavaScript的:
<link rel="stylesheet" href="jquery-ui-1.10.3.custom/jquery-ui-1.10.3.custom.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#dialog-modal" ).dialog({
height: 380,
width: 500,
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
HTML:
<div id="dialog-modal" title="Please Note:" class="content-list">
<p>If you are taking advantage of our 21 day risk free trial <strong>your credit card will not be charged for 21 days</strong> after you receive your new biofeedback headband.</p>
<ul>
<li>Only Available for residents of the USA</li>
<li>No Risk - 100% Money-Back Guarantee</li>
<li>If you’re not satisfied we even pay for your return shipping</li>
</ul>
</div>
謝謝。
您可以使用jquery cookie插件 。 如果包含該庫,則可以執行以下操作:
$(function () {
if (!$.cookie("notice-accepted")) {
$("#dialog-modal").dialog({
height: 380,
width: 500,
modal: true,
buttons: {
Ok: function () {
$.cookie("notice-accepted", 1, { expires : 30 });
$(this).dialog("close");
}
}
});
}
});
注意:您將要添加style="display: none;"
對話框<div>
因此當您不打開對話框時不會顯示該對話框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.