Maximize browser window using Javascript



The key to maximizing the browser window in Javascript is the window.resizeTo() function, which would resize the window to any specified size. The function somehow needs to get the screen’s width and height to be supplied as parameter, and the window itself need to be moved to the top left corner of the screen using the window.moveTo() function so that it will be displayed in full.

 The following example will maximize the browser window as the page loads:

<html>
<head>
	<script language="JavaScript">
		window.moveTo(0, 0);
		window.resizeTo(screen.width, screen.height)
	</script>
</head>
</html>

The browser window will maximize if a user click on the URL as in the following example:

<html>
<head>
	<script language="JavaScript">
		function maximizeme(){
			window.moveTo(0, 0);
			window.resizeTo(screen.width, screen.height)
		}
	</script>
</head>
<body>
	<a href="javascript:onclick=maximizeme()">Maximize</a>
</body>
</html>

 


Posted on 06.09.2008 and categorized under web

Comment Form


  • ayaz: Thanks for the tip.
  • TrueColorTech: Awesome Tip, I have been wanting that option for a while now!
  • iGadget: If this would work, it'd be really nice. However, when I use the command described in your post, I get the following error (twice): Could not conne
  • Alan: fedora 10 is so cool and i have fedora 10 too!
  • Kyle: Forgot to swing back by here after finding version 5.1.3 available, posted about it here: http://yokohead.com/2009/01/google-gears-in-firefox-x64-for

Categories