问题
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.
回答1:
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 ... :)
回答2:
Please first add a ,
at the end of the following line
buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } }
IE expects that all options be closed off via ,
Let's see if that does the trick (its probably good to ask what version of IE is this failing on?)
来源:https://stackoverflow.com/questions/4265316/auto-size-a-jquery-ui-dialog-in-internet-explorer