Ask a Jedi: Sizing a window with ColdFusion

This post is more than 2 years old.

Jay asks:

OK, I should know how to do this and I feel stupid for asking but I am going to anyway.

Is there a simple way in Coldfusion to grab the current size of the window you have opened?

This isn't stupid - but is one of the many questions that reveal that you may have forgotten that ColdFusion is completely server side. ColdFusion's only interaction with the browser is with the HTML returned via the web server.

So with that being said, you can use JavaScript to check the size of the window. I found a few methods, but these properties seem to work fine in Firefox. (And I'm too lazy to start Parallels just for IE, so I'm fine with people correcting me.)

window.outerWidth window.outerHeight

You can check these values and if they are too small, resize the window. Consider this complete example:


<head> <title>Min Size Test</title> <script> function checkMinSize() { if(window.outerWidth < 500) window.resizeTo(500, window.outerHeight); if(window.outerHeight < 500) window.resizeTo(window.outerWidth,500); } </script> </head>

<body onLoad="checkMinSize()">

</body> </html>

All this does is check the width and height. If either are less then 500 pixels, the window is resized to the correct size. I do this in two steps because it is possible only one dimension is too small.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA