Auto size a jQuery UI dialog in Internet Explorer
17,037
I'm having success with width: 'auto'
sizing jQuery UI dialog using the following "patch" (for IE) :
(function($) {
var fixDialogAutoWidth = $.noop;
if ( $.browser.msie ) {
fixDialogAutoWidth = function(content) {
var dialog = $(content).parent('.ui-dialog');
var width = dialog.innerWidth();
if ( width ) dialog.css('width', width);
}
}
var _init = $.ui.dialog.prototype._init;
$.ui.dialog.prototype._init = function() {
// IE magick: (width: 'auto' not working correctly) :
// http://dev.jqueryui.com/ticket/4437
if ( this.options.width == 'auto' ) {
var open = this.options.open;
this.options.open = function() {
fixDialogAutoWidth(this);
if ( open ) open.apply(this);
}
}
// yet another bug options.hide: 'drop' does not work
// in IE http://dev.jqueryui.com/ticket/5615
if ( $.browser.msie && this.options.hide == 'drop' ) {
this.options.hide = 'fold';
}
return _init.apply(this); // calls open() if autoOpen
};
})(jQuery);
Just load this code after jquery-ui.js has loaded ...
Note that according to the ticket http://dev.jqueryui.com/ticket/4437 we shouldn't be using width: 'auto' but I just couldn't live without it ... :)
Comments
-
Shahin almost 2 years
How can I autosize a jQuery UI dialog in Internet Explorer?
This code is OK in Firefox, but not in Internet Explorer.
$('#dialog2').dialog({ autoResize: true, show: "clip", hide: "clip", height: 'auto', width: 'auto', autoOpen: false, modal: true, position: 'center', draggable: true, open: function (type, data) { $(this).parent().appendTo("form"); }, buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } } });
My HTML element is a DIV.
-
Salman Paracha over 13 yearsany results based on my above recommendation?
-
Shahin about 13 yearsi tried. i did add this code after jQuery-ui.js but it does not work yet :(. IE8
-
kares about 13 yearsi'm sorry it did not work for u - i would start by logging and checking the value of
dialog.innerWidth()
infixDialogAutoWidth
...