Posted in JavaScript | Posted on 05-07-2007 | 4,244 views
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.)
2window.outerHeight
You can check these values and if they are too small, resize the window. Consider this complete example:
2
3<head>
4<title>Min Size Test</title>
5<script>
6function checkMinSize() {
7 if(window.outerWidth < 500) window.resizeTo(500, window.outerHeight);
8 if(window.outerHeight < 500) window.resizeTo(window.outerWidth,500);
9}
10</script>
11</head>
12
13<body onLoad="checkMinSize()">
14
15</body>
16</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.


For instance, if I had an invisible div with Ray's picture and bio that showed visible when the mouse hovered over his name, I could put the photo side by side with the bio on a wider browser window, and skip the photo and just have the bio on a smaller window.
[Add Comment] [Subscribe to Comments]