Set the browser window size using JavaScript

See About this website for notes about tips and links provided.

(This page had 10,000 views between Oct 2005 and Dec 2006 [rank: 1]; if this information helps you, consider making a small donation using PayPal - think of it as a tip!)

Date created: ~2003; Note: This doesn't seem to work in Firefox v1.5 (Dec 2005)

You may want to control the size of the browser window which opens when a viewer accesses your web page. The default behavior is for the browser window to open at its last setting (e.g. maximized, or resized according to the viewer's preference). You can force the browser window to open at a specific pixel size (width and height). The viewer can still resize, maximize, or minimize the window once it has opened, but re-opening or refreshing the window will pull it back to the settings you have defined. You will use some simple JavaScript to perform this function. You need to add code to the <head> section and the <body> tag.

In the <head> section

<script>
function changeScreenSize(w,h)
{
window.resizeTo( w,h )
}
</script>

In the <body> tag

<body onload="changeScreenSize(500,300)">

In this example, the window size has been set to 500 pixels wide and 300 pixels high. Experiment with different width/height pixel values to get the effect you want.