I use modal dialog on page open and I'd like to show it once for each user. Here is the code,but it doesn't work
<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
$("#dialog").dialog({
modal: true
});
$(function() {
if ($.cookie('shownDialog') != 'true') {
$('#dialog').dialog();
}
$.cookie('shownDialog', 'true', {expires: 7});
});
$("#close").click(function(event) {
event.preventDefault();
开发者_StackOverflow社区 $(this).closest(":ui-dialog").dialog("close");
});
});
// ]]>
</script>
Can someone help me to fix code?
I'm guessing you're seeing the dialog always instead of once per user.
$(document).ready(function(){
$("#dialog").dialog({
modal: true
});
This part is going to show the dialog immediately, before ever reaching your check for display.
You should get rid of it and move your modal option into the if block instead:
<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
$(function() {
if ($.cookie('shownDialog') != 'true') {
$("#dialog").dialog({
modal: true
});
}
$.cookie('shownDialog', 'true', {expires: 7});
});
$("#close").click(function(event) {
event.preventDefault();
$(this).closest(":ui-dialog").dialog("close");
});
});
// ]]>
</script>
精彩评论