2011-08-29 104 views
6

我想问为什么jQuery UI对话框自动将宽度设置为“auto”?jQuery UI对话框自动设置iframe的宽度

下面是我的iframe要构建一个对话框。

<iframe id="pklist3" class="ui-dialog-content ui-widget-content" frameborder="0" src="http://localhost/picker" style="width: 570; height: 410px; min-height: 0px;" scrolltop="0" scrollleft="0"> 

它具有固定的宽度和高度。但每次我调用“对话框”(“打开”)时,宽度都会自动变为“自动”。至于它的高度设置为一些固定值(我想它是由jQuery UI计算的)

当初始化对话框时,我已经设置了宽度和高度。 像这样:

var dg = {}; 
dg.title = this.title; 
dg.autoOpen = false; 
dg.modal = true; 
dg.overlay = { 
opacity: 0.4, 
background: "#000" 
     };        
dg.resizable = false; 
$('#pklist3').dialog(dg); //iframe width is still fixed value up to this line 

但经过这样的:

$('#pklist3').dialog('open'); //iframe width gets "auto" automatically 

这是一个已知的行为呢?有没有一种方法可以自己定义iframe的宽度和高度?

PS。我使用jQuery UI 1.8.16和jQuery 1.6.2 ,并且当我启动对话框时,iframe的宽度不会改变。它只是我称之为后更改对话框(“公开”)

回答

10

万一别人处理这个问题,并绊倒在这篇文章中,像我一样,我最终找到了一个适用于我的解决方案:http://enotacoes.wordpress.com/2012/04/19/setting-iframe-width-in-jquery-dialog/

基本上,您可以在iframe样式中设置最小宽度,而不是(或另外)使用宽度样式。

<iframe src="someurl" width="100%" height="100%" frameborder="0" 
     scrolling="no" style="min-width: 95%;height:100%;"/> 
0

您可以在初始化定义元素width

$('#something').dialog({ 
    width: '100px' 
}); 
+0

已经做到了。我再次编辑我的问题。感谢您的回应:D –

+0

对话内容如何?它有固定的宽度吗?你也可以尝试编辑UI CSS来定义一个'min-width',但不确定它会起作用。 – yoda

+0

:D我甚至试着用一个空的iframe。 iframe宽度仍然更改为“自动”。真的很奇怪的行为。 –

0
<iframe src="<%= AppConfig[:running_url] %>" frameborder="0" scrolling="no"></iframe> 
<script type="text/javascript" charset="utf-8"> 
    $(document).ready(function() { 
    $("iframe").height($(window).height()); 
    $("iframe").width($(window).width()); 
    }); 
</script> 

我觉得scrolling="no"是必要的。