kylebellamy
kylebellamy

Reputation: 993

jQuery Dialog set jquery.cookie for one viewing only on any close

I want the standard dialog to open only once on page load for the first time a person visits the site then never again. I've added in the click anywhere to close option and linked in the jquery.cookie.js but do not have the close button as the company owner does not want that on there, just the X in the corner and the click anywhere to dismiss.

It would be great to have the cookie set on display of the dialog rather than on the close if that's possible.

Here is the JS:

 <script type="text/javascript">
    $(function () {

    $("#dialog").dialog({
        bgiframe: true,
        modal: true,
        height: 400,
        width: 700,
        dialogClass: 'fixed-dialog',
        open: function() {
        jQuery('.ui-widget-overlay').bind('click', function() {
            jQuery('#dialog').dialog('close');
        })
    }

    });
});
</script>

And the basic modal:

<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

Thanks for anything you can help with!

Upvotes: 0

Views: 445

Answers (1)

Andrew S
Andrew S

Reputation: 136

You could check for the cookie in document.ready and bind/call the dialog box on load or just not bind it to any click event.

$(document).ready(function(){
if(CheckCookie())
{
$("#dialog").dialog({
        bgiframe: true,
        modal: true,
        height: 400,
        width: 700,
        dialogClass: 'fixed-dialog',
        open: function() {
        jQuery('.ui-widget-overlay').bind('click', function() {
            jQuery('#dialog').dialog('close');
        })
    }
}
});

function CheckCookie()
{
//cookie check.
//return true if cookie doesn't exist
}

Upvotes: 1

Related Questions