Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 836
matthew_360 Avatar asked Jan 24 '23 15:01

matthew_360


2 Answers

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().

However, those will not work. Instead, use:

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

P.S. Rsolberg: The poster did say modal dialog window. That seems like the way I'd describe it. I'm not sure that could be interpreted as being related to jQuery. I'd remove the jQuery answer in order to avoid confusion.

like image 124
Josh Mouch Avatar answered Feb 01 '23 23:02

Josh Mouch


You'll want to identify the element or container ID and do something like this:

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.

Edit
Within the javascript functions above, MyModal will be the ID of the container or modal. For example, if you are using a DIV for the outer element of your modal, you would set the DIV up like this:

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

EDIT #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')
like image 32
RSolberg Avatar answered Feb 01 '23 23:02

RSolberg