Many people are probably familiar with the fact that most browsers allow Javascript code to be entered in the address field. That’s the magic behind bookmarklets, which simply spare the user the hassle of manually typing long, convoluted and obfuscated Javascript statements.
While it’s usually pointless to do so, there is one case in which it makes perfect sense: resizing the browser window to an arbitrary size, in order to test what a website looks like. Essentially, by setting the browser window to a size such as 1024 x 768, one can have a relatively reliable idea of what the current website would look at that screen resolution. In truth, one would have to take the graphical elements of the operating system in question, but it’s usually a fine way to get an idea.
The code to do so is very simple:
window.resizeTo(width, height);
Therefore, if we want to set the window to 1024 x 768 pixels, we type the following pseudo-address:
javascript:window.resizeTo(1024, 768);
and press enter. A few things worth noting:
- Capitalization is important. It is resizeTo, with a lowercase “r” and a capital “T”
- There is no space, nor any slash, after the colon
- The width and height have to be separated with a comma, and (of course) have to be integers
- The semicolon at the end is optional, but if you’re a programmer it will be natural to type it
- In some browsers, you can omit the “window.” part, as the current window is implied
This is all good and great, and works in most browser.
Safari, however, only allows this intermittently. Since I spent some time making tests to figure it out, here is a tip: Safari will execute resizeTo only when there is one (and only one) tab in the window.
I’m not sure whether this is caused by a specific setting on my machines, or if it’s a default, or if it can be even changed, but I can see the point in this behavior. Since some websites have the bad habit of resizing the current window to full screen (an annoying and pointless habit, if you ask me), Safari blocks the execution of such command in order not to disrupt the concurrent navigation of different websites/pages.
It’s as if it said: “if this is your own window, do what you want with it; if not, you’ll have to respect your tab brothers.”
So, if resizeTo isn’t working for you, drag that tab out of the bar so it’s instantly opened in its own window, and try again.