简体   繁体   中英

jquery ui dialog, open new dialog and close dialog behind

My Site has a footer that open 4 different dialogs and load content to them from independent pages.

The footer pages can be opened independently if you enter them from search engine or type the url.

I have a function that opens the footer dialogs:

function FooterPopup(){
    $(document).ready(function(){
        $('#footerContactUs').on("click",function(){
            var $dialog=$('<div></div>').load($('#footerContactUs').attr('href')).dialog({
                close: function(event,ui){$(this).remove ();},
                autoOpen:false,
                width:700,
                height:610,
                resizable:'false',
                modal:true,
                show:'blind',
                hide:{effect:'blind',duration:300},
                dialogClass:'Contact'
            });
            $dialog.dialog('open');
            return false;
        });
    })
}

The independent pages have link that open another dialog in a different function,

so I have 2 situations :

1.dialog opens on top of another dialog.

2.dialog opens from an independent page.

code:

function Consult(){
    $(document).ready(function(){
        $('.ConsultHotels').on("click",function(){
            var $dialog=$('<div></div>').load($('.ConsultHotels').attr('href')).dialog({
                modal:true,
                close: function(event,ui){$(this).remove();
                $('.ui-datepicker').remove();},
                autoOpen:false,
                width:750,
                height:590,
                resizable:'false',
                show:'blind',
                hide:{effect:'blind',duration:300},
                open:function(event,ui){$('body').find('.ui-dialog-content').eq(0).dialog("close");},
                dialogClass:'ConsultClass'
            });
            $dialog.dialog('open');
            return false;
        });
    });
}

My problem is that I dont Know how to close the "parent" dialog from the first situation without closing the dialog in the second situation.

Please help,

Thanks.

Why not just close any open dialogs before opening the new dialog?

$('.ConsultHotels').on("click",function(){
  // first close any open dialogs.  This approach is used in stead of just doing a .hide()
  //  because it will invoke any dialog close callbacks.
  $('.ui-dialog-titlebar-close:visible').click(); 

  // now initialize your dialog.
  var $dialog = $('<div></div>').load($('.ConsultHotels').attr('href')).dialog();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM