JavaScript
  Home arrow JavaScript arrow 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  
Moblin 
JMSL Numerical Library 
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


    (Page 1 of 5 )

    This series of articles mainly concentrates on working with browser windows and their sub-windows in JavaScript. You can reuse these scripts to inject into server side controls easily (especially in .NET and Java).

    All of the examples in this series can be directly tested by copying and pasting the entire code (of each section) into any text file with the extension .HTM and opening it using a browser.

    How to resize the current browser window using JavaScript

    I already contributed a few articles on JavaScript to this website.  If you are new to JavaScript, I suggest you take a look at them before proceeding further.

    Now, let us try to develop a simple script (JavaScript) to resize the current browser window. Take 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 Apply(w,h)
    {
          window.resizeTo(w,h); //To resize the window to a specific pixel
    size
          //window.resizeBy(w,h); //To increase or decrease the size of the
    window by a fixed pixel amount,
    }

    function Button1_onclick() {
          var w = document.all("txtWidth").value;
          var h = document.all("txtHeight").value;
          Apply(w,h);
    }
    //-->
                </script>
          </head>
          <body>
                <form  id="form1">
                      Enter width:<input  type="text"  id="txtWidth"
     NAME="txtWidth"  value="400"><br>
                      Enter height:<input  type="text"  id="txtHeight"
     NAME="txtHeight"  value="200"><br>
                      <input  type="button"  value="Show"  id="Button1"
     name="Button1"  onclick="return Button1_onclick()">
                </form>
          </body>
    </html>

    Actually, within the above code, the “meta” tag is not necessary.  Because I developed the above code using Visual Studio.NET 2003 Enterprise Architect, it was automatically added to provide its full-featured mechanisms.  The explanation for the above code is discussed in the next section.

    Within the above code, I managed to create two textboxes named “txtWidth” and “txtHeight” and a button named “Button1.”  When the button (button1) is clicked, the control goes to the function “Button1_onclick.”  This function mainly captures the values (width and height) given by the user and finally calls another function, “Apply” (along with passing those values).

    The function “Apply” mainly contains the following statement:

          window.resizeTo(w,h); //To resize the window to a specific pixel

    The “window” is a built-in object in JavaScript which contains a method, “resizeTo.”  The method accepts two parameters, width and height.  The method automatically resizes the window to the specified width and height.  The above statement resizes the current browser window (on which your web page is displayed) to the width and height values you specified within the textboxes.  Let us consider another alternative:

          window.resizeBy(w,h);//To increase or decrease the size of the
    window by a fixed pixel amount,

    The “window” object contains another method, “resizeBy,” which also resizes the current browser window.  The only difference between “resizeTo” and “resizeBy” is that the first one resizes the window to specific pixels and the latter resizes by increasing or decreasing the size mentioned.

    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 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
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables






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