Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  151] [ 3]  / answers: 1 / hits: 18115  / 11 Years ago, fri, february 7, 2014, 12:00:00

I need this popup to show only once for each visitor. When the user clicks the close button the cookie should trigger and set the popup to not show for 30 days. I have tried installing a cookie myself, but to no avail as I have limited understanding of JavaScript. I've read several posts on here relating to this, but they id not help me.



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>


Thanks.


More From » jquery

 Answers
185

You could use the jquery cookie plugin. If you include that library, you can do the following:



$(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);
}
}
});
}
});


Note: You will want to add style=display: none; to your dialog <div> so it is not displayed when you do not open the dialog.



Demo on JSFiddle


[#72659] Thursday, February 6, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminkyrap

Total Points: 631
Total Questions: 89
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;