Search code examples
javascriptjqueryuser-interfacemodal-dialogalignment

javascript modal dialog aligning to middle of the page


$("#divDisplayPopUp").dialog({
                autoOpen: false,
                modal: true,
                height: 436,
                width: 939,

            });

This code doesnt align the popup into the center of the page.

And its alignment differs in Firefox, IE and Chrome.

Can anyone suggest how to align it to the centre, irrespective of browser?

Thanks.


Solution

  • I think this your answer.

    $(document).ready(function(){ 
       var maskHeight = $(document).height();
       var maskWidth = $(window).width();
    
       $('#divDisplayPopUp').css('top', (maskHeight - $('#divDisplayPopUp').height()) / 2);
       $('#divDisplayPopUp').css('left', maskWidth / 2 - $('#divDisplayPopUp').width() / 2);
    });
    

    I use many times of this and never see any problem.