Karen Stella

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromKaren Stella
ToMe
SubjectIs it possible to spec the browser window width with html?
Date26 March 2007 20:47
I'm a non-web designer making my own page...
I'd like to have the website reset the user's browser window to a specific
width.
I'm guessing the answer is no, as I have spent an hour digging around on
yours and other sites, but can you confirm that?

I would guess yes for Java, but i haven't found a page I can snag the code
from, and I am otherwise java-illiterate.

I think I might try sticking the page inside a frame, so I can at least box
the sucker. It has a repeating background tile, so a single cell table won't
help.

Many thanks,
Great Site! Especially when Moosified.
Karen
FromMe
ToKaren Stella
SubjectRe: Is it possible to spec the browser window width with html?
Date27 March 2007 12:48
Karen,

> I'd like to have the website reset the user's browser window to a specific
> width.

With HTML alone, this is not possible.

> I would guess yes for Java, but i haven't found a page I can snag the code
> from, and I am otherwise java-illiterate.

I assume you mean JavaScript (a totally different language to Java). Yes,
this is possible, using something like this:
<script type="text/javascript">
window.resizeTo(500,300);
</script>

Note, however, that there are several limitations:
1. The user may have disabled this functionality
2. The user may not have as much screen space as you think - many browsers
will not allow the page to resize to larger than the space they have
available
3. resizeTo resizes the _outside_ of the window, not the inside - browsers
will all have different sizes used by their toolbars, and you cannot
reliably work out how much space that is
4. Most browsers will not allow the window to resize if it is already
maximised
5. Resizing fails in most browsers if the user uses tabs

> I think I might try sticking the page inside a frame, so I can at least
> box the sucker. It has a repeating background tile, so a single cell table
> won't help.

Why not just make the containing element be the required size? You should
use a doctype that triggers standards compliant rendering:

Strict HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Transitional HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

Then use CSS like this:
html { margin: 0; padding: 0; }
body {
  margin: 0 auto; /* use margin: 0; if you do not want it centred */
  padding: 0;
  height: 300px;
  width: 500px;
}
Then apply the tiled background to the body.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromKaren Stella
ToMe
SubjectRe: Is it possible to spec the browser window width with html?
Date27 March 2007 15:01
Thanks Tarquin!
I am mainly trying to shrink the window so the feel (including the tile) is
"letter size" not wide, but that's a good point about tabbed browsers, it
may not be worth pursuing.
I will play with some of these concepts. All my html knowledge is 10 years
old, so I haven't even delved into CSS. Pathetically, I am using Quark to
build this so it's fairly rudimentary and requires a lot of text editing
after the fact.
Many Thanks for the code snippets!

-Karen
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.