Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set browser window size and position via URL parameters Web Browsers
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.]
    •    
  • Currently 1.56 / 5
  You rated: 1 / 5 (9 votes cast)
 
[19,760 views]  

Set browser window size and position via URL parameters | 36 comments | Create New Account
Click here to return to the 'Set browser window size and position via URL parameters' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set browser window size and position via URL parameters
Authored by: acaltabiano on Apr 22, '09 08:03:24AM

Like the hint, will probably implement it.

I really wish that Safari would remember the sizes you set for the "minimized" size. I hate having it dictate what size is "minimized" almost at its own will.

*sigh*

---
timing has an awful lot to do with the outcome of a raindance
http://www.randombob.net



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: acaltabiano on Apr 22, '09 08:06:25AM

Note that it doesn't seem to work if the page is a new tab in another window.

---
timing has an awful lot to do with the outcome of a raindance
http://www.randombob.net



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 22, '09 03:45:56PM

Perhaps I should have made it clear that I never use tabs and had not tested this.

Does this make it useless for tabs or just not as satisfactory as it might be?



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: simsamsep on Apr 22, '09 08:19:58AM

In my opinion, using scripts like this is a bad habit. I absolutely detest web sites that determine size and position of the browser window and I am certain that I am not alone.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 22, '09 09:19:09AM

The hint (which is not limited to Mac OS X of course) is about resizing when loading the browser's homepage. However, I also dislike websites who do this for me. But well, as long as Firefox doesn't even care to implement a Mac-like zoom, I guess many people feel different about the optimal size and positition...



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Lou Kash on Apr 22, '09 08:37:17AM

Personally, I strongly dislike sites which alter the window size and position. As a consequence, I'm avoiding to visit them as much as possible...



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: asmeurer on Apr 22, '09 09:12:16AM

Please don't do this. I have my Safari window set to a very specific size, and I don't want your site changing it because it thinks it knows what I want better than I do. Most people nowadays use tabbed browsing, so if you change the size of your user's window, you are changing the size of every one of their windows. Good web design is making your page fit well on all reasonable sizes of windows, not making the window fit your webpage.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: ljharb on Apr 22, '09 09:58:50AM

As a web designer and a computer user, this hint makes me cry.

1) You NEVER force environment changes on a user.
2) You design for ALL possible resolutions - if you need a specific resolution you are not meant to be a designer.
3) You didn't even use named URL parameters, so it's highly likely that an Ad network's parameter, or an actual useful script parameter, will get used for resizing, and that's bad.

This hint should be removed as quickly as a hint that says "You should put blinking text all over your webpage!"



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 22, '09 11:12:23AM

Alternatively, we could all actually READ the hint, and understand that it is ONLY about a user instructing his/her own browser to load a page of his/her choice using some specific dimensions and location. Absolutely nothing wrong with that.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 22, '09 03:48:56PM

I could not have put it better myself - thanks.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: gidds on Apr 22, '09 12:10:48PM

If only more designers felt as you do!

I heartily, heartily agree with you, but I couldn't tell you how many sites just refuse point-blank to work with my preferred window size and font. I don't think either are exceptional -- about 800 pixels wide, and Optima 16.5-point -- but most sites want to be wider so they can fit in all the sidebars and adverts and sponsor's messages and stupid links and inane widgets and promos and Amazon links and syndicated content...

I can understand all that on a site's front page, but to squeeze all that into every single page on a site? Does *anyone* come back for more?

I've managed to hide the worst of it in some sites, by defining by own CSS stylesheet. (AdBlock does some of that, of course, but I use both Firefox and Safari both at home (OS X) and work (Windows), so I prefer a solution that works on all four.) But it takes time, and it's only worth doing for sites with good content; the rest I just don't visit.

We need to shout from the rooftops that THE WEB IS NOT AN ADVERTISING BROCHURE!!! HTML is about content, not appearance! It's *designed* to be shown in different ways, on different machines and displays, using different fonts and layouts and technology. You shouldn't even assume the user has a mouse -- and yet so many sites make ludicrous assumptions about exactly how many pixels high a block of text will appear...

If I want to watch a movie, I'll go to a cinema. If I want to read a brochure, I'll pick one up. If I've come to your web site, then it's probably because I want to find something in particular, so it's in your interest to let me find it! Get rid of all the extraneous crap, all the intros and animations and forced layout and unnecessary clicks, get out of my way and let me use your site. Or there are plenty of other sites I could visit.

[fx: calms down a bit]

Sorry about the rant. It's just something I feel strongly about (can you tell?). Normal transmissions will be resumed as soon as possible. Meanwhile, here's some music.

---
Andy/



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: robtain on Apr 22, '09 09:59:47AM

I agree with other posters here that this is a bad idea. I recently did a search around the 'Net for a way to resize a browser window that contained a video clip. Almost every answer to my query came with the caveat that it shouldn't be done because it was disruptive, intrusive and unnecessary.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: dronkert on Apr 22, '09 11:24:44AM

Very bad practice to force window size and position on the user! I really hate it when that happens to me.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: rxcfc on Apr 22, '09 02:29:01PM

Maybe I'm wrong, but I thought the OP was suggesting that you use this as your Safari starting page to set your browser window to the size that you personally like. I didn't think he was suggesting that people put this on any public pages.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 22, '09 03:06:50PM

I am the OP and I had not intended my post to be anonymous. Rob has kindly agreed to correct this for me.

rxcfc is correct. 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.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: baltwo on Apr 22, '09 04:28:22PM

Then, if that's the case, this AppleScript application (which uses Safari, as an example) does the same thing without the cryptic URL tags. Change the bounds to suit your needs.

ell application "Safari"
activate
set the bounds of the front window to {552, 106, 1567, 1004}
end tell

Put it on the Dock and you're good to go.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 23, '09 02:56:51AM

A devilish device - perhaps it should be 'Tell' !



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: baltwo on Apr 24, '09 04:40:06AM

Ooops. A copy and paste error. Use Tell



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: ThomPatterson on Apr 22, '09 03:29:36PM

This is a rather brilliant idea that I wish I would have thought of earlier! I always want Safari to be fully-maximized on my second monitor, but depending on where the window was when I last closed that is not necessarily how it will open.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Stormchild on Apr 22, '09 04:27:11PM

This is a brilliant tip! I've often lamented the fact that I can't set a default size and position for Safari windows (as I had this feature for many years in OmniWeb).

You could even combine it with SafariStand's ability to block websites from moving or resizing your browser windows, by adding an exception for "localhost" or whatever URL you use for your startup page, and allowing those features for your local URL only. I don't want to allow all sites to do this, so this would be ideal.

And to all of you who are complaining about this as if it was a suggestion to mess with *other people's* browser windows, you have completely missed the point. It's been explained already, so I won't reiterate it, but jeez, have your morning coffee before you start ranting like an idiot (I thought the purpose of this tip would have been totally obvious even to someone still half-asleep, but I'll give you the benefit of the doubt).



[ Reply to This | # ]
SafariStand won't do that
Authored by: martyskinner on Apr 22, '09 09:12:30PM

The ability to block pages from resizing the window is in SafariStand's Advanced settings. It's Site Alternation options don't seem to have a way to undo this Advanced option, or at least I couldn't find anything that remotely matched.

---
/Marty



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 22, '09 05:11:48PM

Alternatively: add a bookmark for the following, put in the Bookmarks Bar and make sure it's listed high in the list to get a Cmd-n shortcut to resize any active window:

javascript:moveTo(10,10);resizeTo(1000,700);

Unfortunately this forum does not allow javascript: links in HTML, but Reset window position gives you a headstart for bookmarking ;-)



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 23, '09 02:46:29AM

This works for me with Mozilla browsers but I have not been able to get it to work with WebKit browsers. I had the same experience with JavaScript in my home page slot, ie OK with Mozilla but not working with WebKit.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 23, '09 03:15:51AM

Strange. The above bookmarklet works fine in both Safari 3.2.1 and 4 beta on my Intel Macs.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 23, '09 03:19:37AM

And true, for the homepage slot both Safari 3 and 4 yield:

Safari can't use JavaScript for this action.
Safari can't run the script "moveTo(10,10);resizeTo(1000,700);" because Safari doesn't allow JavaScript to be used in this way.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 24, '09 04:29:22AM

Sorry - I cannot repeat my difficulty - it works perfectly well in all Safari and iCab bookmark locations. Pity about the silly home page restriction. This may be a better way of doing this than my original hint - I will give it further thought.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: zoff on Apr 24, '09 04:27:47AM
I've been using:
javascript:self.moveTo(900,0);self.resizeTo(1020,screen.availHeight);
to resize Safari windows, but since Safari 4 it doesn't resize a window with multiple tabs, only single tabbed windows.

[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Lui-g on Apr 24, '09 04:35:19AM
My first three links in Safari are called: "<< LEFT", "MAX!" & "RIGHT>>" These can be called up with Apple + "1" or "2" or "3" respectively.

<<LEFT makes a browser window take up the left 50% of the screen; MAX! makes the browser take up the whole screen; and RIGHT>> makes a browser window take up the right 50% of the screen. This way, you can easily have two windows side by side (on a widescreen monitor), without manually resizing.

The code for the links is:
  • <<LEFT javascript:self.resizeTo(screen.availWidth/2,screen.availHeight);self.moveTo(1,0);
  • MAX! javascript:self.resizeTo(screen.availWidth-1,screen.availHeight);self.moveTo(1,0);
  • RIGHT>> javascript:self.resizeTo(screen.availWidth/2-1,screen.availHeight);self.moveTo(screen.availWidth+1,0);
**Note, the reason the window is placed at coordinates 1,0 rather than 0,0 was to circumvent a Safari bug. Other variations include:
  • <<800 - which makes a 800px wide window to the left of the screen (edit the 800 to anything else you like) javascript:self.resizeTo(800,screen.availHeight);self.moveTo(1,0);
  • >1024< - makes a window 1024px wide centered on the screen. javascript:self.resizeTo(1024,screen.availHeight);self.moveTo((screen.availWidth-1024)/2,0);
Hope someone finds this useful - I do. Lui-G

[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 24, '09 04:37:03AM

I am sure many will find this useful. Perhaps best to use (1,1) rather than zero for Mozilla browsers.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: zoff on Apr 24, '09 04:40:59PM

None of the scripts work on a window with multiple tabs. They used to before 4 beta. Does it work for anyone with Safari 4 beta?



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 24, '09 04:38:21AM
I particularly like the various bookmark bar suggestions and am considering if this is the way I will go in future. However my main concern is finding a browser (not server) fix for pages such as http://links.open.ac.uk/.

In common with many links pages it uses <base target="_blank"> which has worked well for about 10 years. I would prefer not to change it until I convert to HTML 5.

Unfortunately once JavaScript has been used to alter window size or position most/all browsers stop inheriting size/position for target links. Try hitting a link on the page after using one of the JavaScript methods described here.

Safari appears to use window parameters from an earlier 'session'. Other browsers do other silly things.

I would appreciate it if somebody could point me to a browser JavaScript fix for this.

[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 24, '09 05:59:13AM

This appears not to be problem with Mozilla browsers but Safari and iCab are badly affected.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 25, '09 03:00:59AM
I have reported the 'target' link issue as a WebKit bug at:

https://bugs.webkit.org/show_bug.cgi?id=25392


[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: Neville Hillyer on Apr 24, '09 03:13:58PM
I have made several alterations to http://links.open.ac.uk/window/ including improved local support with links now reflecting user's parameters. The page should now automatically update its links even when used locally.

I now link back to this thread.

I hope I have tested it properly but please report any difficulties.

I still lack a fix for 'target' links - please see my earlier comment or the web page.

[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 24, '09 03:55:35PM

Fun facts:

When using a vertical Dock at the left of the screen, then for both Safari and OmniWeb the x-coordinate 0 is actually located just to the right of the Dock. The y-coordinate has its zero position just beneath the menu bar.

In Firefox (0, 0) is in the top-left corner of the screen, but the y-coordinate must be at least 23, and any x-coordinate smaller than the width of the Dock is ignored as well.

In all these browsers I cannot use JavaScript to move a browser underneath the Dock.

And: both Firefox (3.1 beta) and OmniWeb 5 allow for using JavaScript in the homepage slot.



[ Reply to This | # ]
Set browser window size and position via URL parameters
Authored by: palahala on Apr 25, '09 01:25:00AM

For Safari 4 beta, the problem with JavaScript not resizing or moving when multiple tabs are open, is in fact a reported bug for webkit.

It may actually not be a bug, of course...



[ Reply to This | # ]