JavaScript
  Home arrow JavaScript arrow Page 3 - Start Working With Browser Windows in Java...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Start Working With Browser Windows in JavaScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2006-04-18

    Table of Contents:
  • Start Working With Browser Windows in JavaScript
  • How to move the current browser window using JavaScript
  • How to maximize the current browser window using JavaScript
  • How to open a new pop up window using JavaScript
  • A word of caution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Start Working With Browser Windows in JavaScript - How to maximize the current browser window using JavaScript


    (Page 3 of 5 )

    Now, let us try to develop a simple script (JavaScript) to maximize the current browser window. Have a look at the following code:

    <html>
          <head>
                <meta  name=vs_targetSchema
     content="http://schemas.microsoft.com/intellisense/ie5">
    <script  id="clientEventHandlersJS"  language="javascript">
    <!--
    function MaximizeWindow()
    {
          var offset = 4; //needs to change accordingly with browsers
        window.moveTo(-offset, -offset);
        window.resizeTo(screen.availWidth + (2 * offset), 
                       screen.availHeight + (2 * offset));

    }

    function Button1_onclick() {
          MaximizeWindow();
    }
    //-->
                </script>
          </head>
          <body>
                <form  id="form1">
                      <input  type="button"  value="Show"  id="Button1"
     name="Button1"  onclick="return Button1_onclick()">
                </form>
          </body>
    </html>

    This concept is a peculiar case.  Can we really maximize a browser window using JavaScript? To which my answer is NO.  There exists no direct procedure to maximize a browser window dynamically using JavaScript at all. The best indirect way to achieve the same is to resize the window so that it fits the entire screen!

    Let us consider the following function I used in the above code:

    function MaximizeWindow()
    {
    var offset = 4; //needs to change accordingly with browsers
        window.moveTo(-offset, -offset);
        window.resizeTo(screen.availWidth + (2 * offset), 
                       screen.availHeight + (2 * offset));
    }

    The above is a simple function which uses an indirect way of maximizing a browser window.  I used the “offset” especially to push the border of the browser window a further four pixels to the left and top (mimicking the maximization).  But please be aware that some browsers work with the “offset” value as simply zero.  I leave it to you. 

    We can use the “screen” object to determine the width and height of a desktop screen.  Based the values I receive from “availWidth” and “availHeight” from the “screen” object, I resize the browser window accordingly.

    More JavaScript Articles
    More By Jagadish Chaterjee


       · Hello beginners! you may find this contribution bit worth, when you wanted to...
       · Hi to all, I m a s/w programmer woking on java/jsp on tomcat.I tried the...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT