Automatic jQuery UI dialog box size in Internet Explorer

How can I authorize the jQuery UI dialog in Internet Explorer?

This code is fine 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.

+6
jquery jquery-ui jquery-ui-dialog autosize
source share
2 answers

I have success with the 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 loading jquery-ui.js ...

Please note that according to the ticket http://dev.jqueryui.com/ticket/4437 we should not use the width: 'auto', but I just could not live without it ... :)

+5
source share

First add , at the end of the next line

 buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } } 

IE expects all options to be closed with ,

Let's see if this does the trick (it might be nice to ask in which version of IE this is happening?)

0
source share

All Articles