35

Does anyone know if there is a way to disable scroll bars in the jquery dialog box? The content that I have in the div is 300 px but the dialog is set to 200px. It automatically puts the scrollbars but I do not want them. I will add it myself to the second div that makes it bigger than the window. Any help is appreciated.

8 Answers 8

73

I solved the problem like this:

.dialog({
  title: $(this).attr("data-dialog-title"),
  closeOnEscape: true,
  close: function () { $(this).remove() },
  draggable: true,
  position: 'center',
  width: 500,
  height: 'auto',
  modal: true,
  open: function (event, ui) {
    $('#myDialogId').css('overflow', 'hidden'); //this line does the actual hiding
  }
});
5
  • 1
    Can you explain what you did to disable scrollbar?
    – Meow
    Commented Jan 26, 2012 at 5:29
  • 6
    Just throwing in a quick correction for commenters this particular answer (which I used thanks man btw). What removes the scrollbars is hiding the overflow with that css trickery, very slick. This part does the hiding: "open: function (event, ui) { $('#myDialogId').css('overflow', 'hidden'); }"
    – unrealtrip
    Commented Oct 26, 2012 at 13:40
  • 5
    I would suggest to use this to refer to the dialog'ed HTML element, so: $(this).css('overflow', 'hidden');
    – 7ochem
    Commented Jan 8, 2014 at 9:02
  • Setting things hidden so it doesn't appear is not a fine solution.
    – Augunrik
    Commented Nov 2, 2015 at 7:23
  • It's great to be able to use {height: 'auto'} and still prevent scrolling. Thanks for this one. +1 Commented Nov 10, 2016 at 14:19
10

Do you mean the jQuery UI dialog widget?

You can pass an option when you create it to specify its height, e.g.

$('.selector').dialog({ height: 350 });

Make it taller than the content you’re putting into it, and I suspect you’d be golden.

6

I don't know exactly what you mean by a 'jquery dialog box', but the standard way to disable the scroll bars would be to set the div's overflow property to 'hidden'

put this in your css file:

div.class_name {
  overflow: hidden;
}
4
  • jquery(a javascript wrapper of sorts) has there own dialog boxes. there are options in jquery to do similar things but did not find one for this particular plugin. i cannot just set that property for jquery Commented Oct 25, 2009 at 2:26
  • 3
    jquery is not a javascript wrapper, it's a framework that abstracts out cross-browser issues and simplifies DOM traversal...if you can specify what jquery function you are using to generate the 'dialog box' then i might be able to help...
    – user35288
    Commented Oct 26, 2009 at 0:42
  • 2
    Not sure why this was downvoted so much when it's the proper way of doing things. .ui-dialog-content { overflow: hidden; } for disabling the scroll bars across all dialogs. #myDialogID { overflow: hidden; } for just one. Commented Mar 30, 2013 at 2:33
  • yes, and it should be better to do all the customization in an css file than doing it by javascript callbacks like in http://stackoverflow.com/a/7483426/1627888
    – Yo Ludke
    Commented Apr 30, 2014 at 10:16
3

The overflow:hidden worked for me. When only setting the height/width params the scroll bars would still appear depending on text size and zoom.

3

Solution with no css or fixed Height:

I think the best solution to above problem is to make dialog height dynamic, the height should adjust automatically as per content, when content increases modal height should increase. To do this use the height "auto" option provided by Jquery UI modal , it adjusts modal height as per content so need of add 'overflow:hidden' or 'height:350'

$( "#dialog" ).dialog({
modal : true,
height:"auto"

}); 
1

This removed the scroll bars:

$( "#dialog" ).dialog({
    autoOpen: false,
    resizable: false,
    dialogClass: 'info',
    height: 'auto',
    width: 'auto',
    show: { effect: "blind", duration: 1000 },
    hide: {effect: "explode", duration: 1000 },
    draggable: true,
    open: function (event, ui) {
        $(this).dialog('open');
    },
    close: function (event, ui) {
        cleanup() ;
    }
});
0

In the example below I also added 'resizable = false' for the dialog. So that any overflow text cannot be seen by resizing the dialog.

$("a#registerServerStudio , a#regServer").click(function(e) {
    //alert("login using POST is Clicked");
    e.preventDefault();
    registerSuccess = false;

    regSSDlg = $("#regSS").dialog({
      autoOpen: false,
      height: 280,
      width: 420,
      modal: true,
    resizable: false,
      buttons: {
      },
      close: function() {
        registerSuccess = false;
      },
    show:{effect:'bounce', duration: 100},

    });
  $('#regSS').css('overflow', 'hidden');
    regSSDlg.prev(".ui-dialog-titlebar").css({"background":"#47669E", "color":"white", "font-size":"13px", "font-weight":"normal"}) ;

    regSSDlg.dialog("open");
});
0

Add the following CSS code to hide any dialog scrollbars:

.ui-dialog-content {
    overflow: hidden;
}

Here a small demo (click on "Full page" for better view):

var reconnectDlg = $('#reconnectDlg').dialog({
    minWidth: 500,
    modal: true,
    autoOpen: false,
    close: function(ev, ui) {
        console.log('reconnect');
    },
    buttons: {
        'Reconnect': function() {
            $(this).dialog('close');
        }
    }
});

var reconnectBtn = $('#reconnectBtn').button().click(function(ev) {
    ev.preventDefault();
    reconnectDlg.dialog('open');
});
.ui-dialog-content {
    overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/redmond/jquery-ui.min.css" rel="stylesheet" />

<div id="reconnectDlg" title="Connection failure">
    Lost connection to the server!
    Lost connection to the server! 
    Lost connection to the server! 
    Lost connection to the server! 
    Lost connection to the server! 
    Lost connection to the server! 
    Lost connection to the server!
</div>

<div id="reconnectBtn">Click me!</div>

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