Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The JavaScript FAQ
Prev Home Next

Maximizing a window

Question: How do I maximize a window?

Answer: To maximize the browser window, your code should determine the available screen size and then resize the window to the user's screen size. Note that there is no reliable way to determine the screen size in version 3 of both major browsers (except for calling Java from Navigator 3.x). Therefore, the following sample function maximizeWindow() only works in versions 4 and newer. Try it now:

Here's the source code:
function maximizeWindow() {
 if (parseInt(navigator.appVersion)>3) {
  if (navigator.appName=="Netscape") {
   if (top.screenX>0 || top.screenY>0) top.moveTo(0,0);
   if (top.outerWidth < screen.availWidth)
      top.outerWidth=screen.availWidth;
   if (top.outerHeight < screen.availHeight) 
      top.outerHeight=screen.availHeight;
  }
  else {
   top.moveTo(-4,-4);
   top.resizeTo(screen.availWidth+8,screen.availHeight+8);
  }
 }
}
A couple of remarks:

1. In Windows, maximizing a window is equivalent to

  • moving the window's top left corner to the point x=-4, y=-4 and
  • resizing the window to the screen size plus 8 pixels (in both horizontal and vertical dimensions)
This allows to effectively hide the window borders. Unfortunately, Netscape Navigator 4 requires a signed script to move the window's top left corner off screen, and therefore the above (unsigned) script leaves the window borders visible. (Before changing the window, the Netscape-specific branch of the script checks whether the window is already maximized. If yes, it leaves the window as is.)

2. Note also that JavaScript code cannot change the look of the maximize button (the second button in the top right corner).

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


 
 
  Mirrored with kind permission of Alexei Kourbatov Design by Interspire