Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts

    Is window maximized ?

    Need to know for IE, would do no harm if there is a kode for FF allso

    Found and lost solution on forum (but did not work anyway), so any help welcome.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    This works for FF and IE 7, howewer it is not 100% bullet proof, because user can manualy resize window to the dimensions that then returns true. But this is highly unlikely i.e almost inpossible.

    If anyone can test this on IE 6.0 .... Thanks.


    Code:
         function isWindowMaximized()
         {
         
          if  (window.outerHeight != null)
          {
            //FF
            if (screen.width - window.outerWidth == -8)
            {
              //alert('FF');
              return true;
            }  
          }
          else
          {
            //IE 7.0
            if (screen.width -document.body.clientWidth == 4) 
            {
              //alert('IE');
              return true;
            }  
            
          }
          
          return false;
          }

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I tried it in IE 5.5 and get when maximised:

    screen.width 1024
    document.body.clientWidth 1002

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Of course all of those tests are assuming that there are no vertical toolbars on the desktop as if there were the maximized size would need to deduct the width of the toolbars.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Apart from vertical tool bars, which I have newer seen jet .....

    Philip, could you test that (save as html). In ie document.body.clientWidth gets influenced by 'SCROLL=NO'. I presume you should get '4px', or something, from below example when maximized.

    Is there a way to detect 'SCROLL=NO' from java script ?
    Does 'SCROLL=NO' equals style='overflow:hidden' ?

    Code:
       <html>
         <head>
          <SCRIPT language="javascript" type="text/javascript" >
    
          function isMaximized()
          {
           
           if (navigator.appVersion.indexOf('MSIE 7.0') > 0)
           {
             alert('IE 7.0')
           }
         
           document.getElementById('testDiv').innerHTML = screen.width -document.body.clientWidth;   
          }
          </SCRIPT>
          </head>
          <body   SCROLL=NO  class = 'body' onresize = 'isMaximized()'>
            <div id="testDiv" style = 'float:left;width:100%;background-color:red;'> 
                s
            </div>         
          </body>
        </html>

  • #7
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Just tested it in IE 6, and returns 4 px, so probably the same on all versions of IE. What remains is question of SCROLL=NO, and posibly vertical scroll bars problem...

  • #8
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    This should do it for FF and IE. Comments welcome.


    Code:
    function isMaximized()
         {
         
          if  (window.outerHeight != null)
          {
            //FF
            if((document.getelementsbytagname('body').style.overflow = 'scroll') && (screen.width - window.outerWidth == 17))
            {
              //alert('FF');
              return true;    
            }
            else if (screen.width - window.outerWidth == -8)
            {
              //alert('IE');
              return true;
            }  
          }
          else
          {
            //IE 7.0
            if (document.body.scroll = 'no')
            {
               //alert('IE');
              return true;      
            }
            else if((document.getelementsbytagname('body').style.overflow = 'scroll') && (screen.width - window.outerWidth == 21))
            {
              //alert('FF');
              return true;    
            }
            else if (screen.width - document.body.clientWidth == 4) 
            {
              //alert('IE');
              return true;
            }  
            
          }
          
          return false;
          }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •