Set browser window size and position via URL parameters

Apr 22, '09 07:30:00AM

Contributed by: Neville Hillyer

Setting your home page to a defined size and position results in much more consistency in subsequent windows. So I use the following code to set window size and position, defined by URL parameters, before redirecting to my home page. These parameters are: width of window, height of window, horizontal position of window, vertical position of window, and link to home page.

<body onload='z=window.location.search.substring(1).split(","); s=z.length; if (s>1) { window.resizeTo(z[0], z[1]); if (s>3) { x=z[2]; y=z[3]; if (1>x) { x=1 }; if (1>y) { y=1 }; window.moveTo(x, y); if (s>4) { window.location=z[4] } } }'>
To use this, you can either use this page on my server (it also has further details and a demonstration), or create your own HTML page that uses the above tag. You'd then load that page, with your preferred size and parameter settings, and append your home page URL to the end of the URL. Alternatively, you can copy the page from my server to your local computer, and modify it to meet your needs.

Note that I am only advocating that those who wish to can opt to control the default size/position of their home page. Putting such code on public pages would be most unpopular. My experience is that, for various reasons, a few hours web browsing can result in browsers being closed with the final page in an unwanted position. I am surprised that browsers don't come with a control to at least start the day with user defined window size and position. There has been considerable recent interest in bookmarklets and JS in home page links (does not work for WebKit) to achieve this. My page attempts to provide a simple cross browser/platform solution.

[robg adds: I tried this via the author's page, and it worked as described. Note that, after reading some of the comments indicating some confusion about this hint, Neville sent me some additional clarifying text, which I have now included in the hint itself.]

Comments (36)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090421162146583