0

I'm appending the jquery dialog to body. I'm setting the height to the dialog.

// Create timeout warning dialog
       $('body').append('<div id="sessionTimeout-dialog" title="' 
                        + opts.title 
                        + '"><p>' 
                        + opts.message 
                        + '</p><span id="sessionTimeout-timer"></span>&nbsp;seconds.</div>');

       $('#sessionTimeout-dialog').dialog({
            autoOpen: false,
            resizable: false,
            minWidth: 0,
            width: 300,
            minHeight: 0,
            height: 400,
            modal: true,
            closeOnEscape: false,
            open: function () {
                //removes the right top close(X) button from the dialog
                $(".ui-dialog-titlebar-close").hide();
                //$(this).dialog('option', 'maxHeight', 500);
            },
            buttons: {
                // Logout button, closes the dialog and takes user to logout URL
                "Log Out Now": function () {
                    $(this).dialog('close');
                    //window.location = 'home.php';
                    window.location = ''+opts.logoutUrl;
                },
                // Stay button, closes dialog
                "Stay Connected": function () {
                    latestActivity = new Date();
                    $(this).dialog('close');
                }
            }
       });

But it still showing the gap before the title of the dialog. Please see the attached output dialog. Need quick help on this.

enter image description here

3
  • Are there any CSS styles applied to #sessionTimeout-dialog which could be interfering with jQuery styles? Edit: Or #sessionTimeout-timer?
    – HappyAnt
    Commented May 15, 2019 at 5:55
  • no other styles applied Commented May 15, 2019 at 6:26
  • I would recommend that you try:- - What is in the header content (Session timeout warning)? Please do a right click and inspect. Could be real data with spaces in it. - Test it out with the style with the !important tag. This will force the style to be in place and super-seed any CSS styles. This is how you will confirm that the CSS is not the root cause. - You might need to redraw the dialog again and see if that helps.
    – SlothKing
    Commented May 15, 2019 at 7:13

1 Answer 1

0

I was unable to replicate the issue as you described it. I tested with the following:

$(function() {
  var opts = {
    title: "Session Timeout",
    message: "Your session has timed out.",
    logoutUrl: "logout.php"
  };

  function makeDiv(o) {
    if (o == undefined) {
      o = {
        id: "session-timeout-dialog"
      };
    }
    return $("<div>", o).html(opts.message).appendTo("body");
  }

  function makeDialog(tObj) {
    tObj.dialog({
      autoOpen: false,
      classes: {
        "ui-dialog": "no-close"
      },
      resizable: false,
      minWidth: 0,
      width: 300,
      minHeight: 0,
      height: 300,
      modal: true,
      closeOnEscape: false,
      title: opts.title,
      buttons: {
        "Log Out Now": function() {
          $(this).dialog('close');
          window.location = '' + opts.logoutUrl;
        },
        "Stay Connected": function() {
          latestActivity = new Date();
          $(this).dialog('close');
        }
      }
    });
  }

  $("#trigger").click(function() {
    var timeOut = makeDiv();
    makeDialog(timeOut);
    timeOut.dialog("open");
  });
});
.no-close .ui-dialog-titlebar-close {
  display: none;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<button id="trigger">Trigger Time Out</button>

The height is correct. I suspect, based on your image, that there are other styles being applied that are not shown in your example code. Please Inspect and review all CSS that is applied.

Hope that helps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.