简体   繁体   English

在Javascript中调整模态窗口的大小

[英]Resize Modal Window in Javascript

I'm trying to resize my modal dialog window when certain items are hidden/shown. 当隐藏/显示某些项目时,我正在尝试调整模态对话框窗口的大小。

window.resizeTo(800, 600);

I've tried using code like above, but it doesn't seem to work. 我尝试过使用上面的代码,但似乎没有用。 I think because it is a modal dialog, and not a regular window. 我认为因为它是一个模态对话框,而不是常规窗口。 Any suggestions as to how I could resize this? 有关如何调整大小的建议吗?

If you're trying to resize the modal dialog window from within the window itself, you might be tempted to use the javascript window.resizeTo() or window.resizeBy(). 如果您尝试从窗口本身调整模式对话框窗口的大小,您可能会想要使用javascript window.resizeTo()或window.resizeBy()。

However, those will not work. 但是,这些都行不通。 Instead, use: 相反,使用:

window.dialogWidth='640px';
window.dialogHeight='480px';

PS Rsolberg: The poster did say modal dialog window. PS Rsolberg:海报确实说出了模态对话窗口。 That seems like the way I'd describe it. 这似乎是我描述它的方式。 I'm not sure that could be interpreted as being related to jQuery. 我不确定是否可以解释为与jQuery相关。 I'd remove the jQuery answer in order to avoid confusion. 我将删除jQuery的答案,以避免混淆。

You'll want to identify the element or container ID and do something like this: 您需要识别元素或容器ID并执行以下操作:

document.getElementById('MyModal').style.height = '500px';
document.getElementById('MyModal').style.width = '800px';

If you are using jQuery for this it can be quite a bit easier as you can attach it to the actual show modal function. 如果你正在使用jQuery,它可以更容易,因为你可以将它附加到实际的show modal函数。

Edit 编辑
Within the javascript functions above, MyModal will be the ID of the container or modal. 在上面的javascript函数中,MyModal将是容器或模态的ID。 For example, if you are using a DIV for the outer element of your modal, you would set the DIV up like this: 例如,如果您使用DIV作为模态的外部元素,则可以像这样设置DIV:

<div id='MyModal' class="IFNEEDED">CONTENTS OF MODEL</div>

EDIT #2 编辑#2
Since this is not a "modal" as most would describe today, its more of a new window popup, this line of code should work for you (found it here ): 由于这不是今天大多数人所描述的“模态”,它更像是一个新的窗口弹出窗口,这行代码应该适合你(在这里找到):

window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM