Connecting Tech Pros Worldwide Forums | Help | Site Map

Find Window State - whether window is maximised or minimised

Newbie
 
Join Date: Dec 2007
Posts: 1
#1: Mar 7 '08
How to find a window sate in Java Script ? I want to know whether the window is maximized or minimized ?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 7 '08

re: Find Window State - whether window is maximised or minimised


I'm not sure if this can be done reliably, but you can try finding the size of the window and determine from that whether it's minimised or maximised or otherwise. This link should help.
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#3: Mar 8 '08

re: Find Window State - whether window is maximised or minimised


a coder was close.

alert(screenX)

when minimized, you get -32000 in firefox.
when maximized, you get -4
when restored, you get something else (the position)
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Mar 8 '08

re: Find Window State - whether window is maximised or minimised


Quote:

Originally Posted by rnd me

a coder was close.

alert(screenX)

when minimized, you get -32000 in firefox.
when maximized, you get -4
when restored, you get something else (the position)

Interesting. Do you know what the values are in other browsers? Is there any sort of consistency in this inconsistency (if you know what I mean)?
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#5: Mar 8 '08

re: Find Window State - whether window is maximised or minimised


i was getting tired so i only tested in firebug last night.

here is a test case for your browser.
it seems ok in IE7 and FF2 for me.

Expand|Select|Wrap|Line Numbers
  1. <html><head><title>dans windowstate tester</title></head><body>
  2.  
  3. announce window state in 4 seconds  <input type='button'  id='' name='' onclick="doMin()" value='run' />
  4.  
  5. <script type='text/javascript'>
  6.         function getWindowState() {
  7.             var S = window.screenLeft;
  8.             if (typeof S === 'undefined' ) {
  9.                 S = window.screenX;
  10.             }
  11.         S=parseInt(S);
  12.             if (S < -4000) {
  13.                 return "minimized";
  14.             }
  15.             if (S > -8 && S < 1 ) {
  16.                 return "maximized";
  17.             }
  18.             return "restored:  " + S;
  19.         }
  20.  
  21.        function doMin() {
  22.            document.title = "change the window state now to what you want to test" 
  23.             setTimeout(" document.title=getWindowState(); ", 4000);
  24.         }
  25.  
  26. </script></body>    </html>    
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Mar 9 '08

re: Find Window State - whether window is maximised or minimised


Quote:

Originally Posted by rnd me

here is a test case for your browser.
it seems ok in IE7 and FF2 for me.

It also works in Safari. In Opera, it works with minimized, but not maximized (gives a value of 649).
Reply


Similar JavaScript / Ajax / DHTML bytes