Skip to content Skip to sidebar Skip to footer

Can Jquery Ui Dialog Remember Its Position Between Opening And Closing

I have a JQuery dialog that I dynamically open and close. Everything is working fine except the position of the dialog is not remembered after it is closed and then reopened. The s

Solution 1:

You could use the jQuery UI Dialog "beforeclose" event to store the position and size. You can set both position and size using the "option" method.

Here is what currently works for me:

$(function() {
    $("#dialog").dialog({
        beforeclose: function(){
            $(this).dialog('option', 'position', [$(this).offset().left, $(this).offset().top]);
            $(this).dialog('option', 'width', $(this).width());
            $(this).dialog('option', 'height', $(this).height());
        }
    });
});

$('#dialog').dialog('open')

Solution 2:

You can override the standard close method by returning false on 'beforeclose' and using jquery to hide the dialog:

$.ui.dialog.defaults.beforeclose = function() {
    $(this).closest('.ui-dialog').hide();
    returnfalse;
};

and this to reopen:

$('#list').closest('.ui-dialog').show();

Solution 3:

Take a look at jquery changeset. You'll also find a fix for this

Post a Comment for "Can Jquery Ui Dialog Remember Its Position Between Opening And Closing"