Home arrow JavaScript arrow Page 3 - Start Working With Browser Windows in JavaScript
JAVASCRIPT

Start Working With Browser Windows in JavaScript


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).

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 14
April 18, 2006
TABLE OF CONTENTS:
  1. · Start Working With Browser Windows in JavaScript
  2. · How to move the current browser window using JavaScript
  3. · How to maximize the current browser window using JavaScript
  4. · How to open a new pop up window using JavaScript
  5. · A word of caution

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials