Javascript set browser window size
Asked Answered
V

2

15

What is the best way to set the size of the browser window when the page loads? I think this can be done in JavaScript. Please explain. Here is my code that is not working!

<html>
<body onload="window.resizeTo(640,480)">
<video src="rushmore.mp4" controls="controls">
your browser does not support the video tag
</video>
</body>
</html>
Virtu answered 8/3, 2011 at 21:33 Comment(7)
are you including some more javascript code that could be interfering ?Joe
No! That is the whole page source. I just figured out it doesn't work in Google chrome but it does in IE.Virtu
Don't do this unless you absolutely have to, for UX's sake.Rawlins
Yes I am using Google Chrome. why doesn't it work?Virtu
There is a known bug (feature ;-) it is reported here code.google.com/p/chromium/issues/detail?id=2091Reichenberg
Is there a way I could bypass this bug and have it work in Google Chrome?Virtu
@inquisitive_web_developer - I have posted a comment as an answer as it became to long - hope it helps.Reichenberg
R
5

I put this in an answer as the comment became to long.

The only thing that I have found that is close to the resizing of the chrome window is to use a chrome extension that can resize the window. The actual extension command is chrome.windows.update(...).

Take a look here.

But I am not sure this is what you are looking for.
If it still interests you there are at least 2 extensions that can do this, that I have seen try this one

Be happy and good luck!

Reichenberg answered 8/3, 2011 at 22:59 Comment(1)
Why this is accepted answer: See "Important notes:" in this answer: https://mcmap.net/q/427726/-window-resize-is-not-working-in-chrome-and-operaTartar
H
16

This should do the trick, setting the height and width to your desired dimensions.

window.resizeTo(500,500)

You could set it onload.

<body onload="window.resizeTo(500,500)">
Havens answered 8/3, 2011 at 21:36 Comment(4)
I am not sure that this works in Chrome. (Only if it is a new instance of the browser)Reichenberg
@Julian, good point. From my experience and the following SO post it does not work in any browser with other tabs working, mainly for a popup. #3884616Havens
I just tried it with Chrome as a stand alone window - doesn't work. There is a bug in chromium - see link in comment to question.Reichenberg
This assumes that you are using px (pixels?) Perhaps a percentage of the window's width and height properties to be set to 98% would do a more intuitive approach since there are such a variety of devices that could access this content.. just an idea to be shared here.#8131446Raskin
R
5

I put this in an answer as the comment became to long.

The only thing that I have found that is close to the resizing of the chrome window is to use a chrome extension that can resize the window. The actual extension command is chrome.windows.update(...).

Take a look here.

But I am not sure this is what you are looking for.
If it still interests you there are at least 2 extensions that can do this, that I have seen try this one

Be happy and good luck!

Reichenberg answered 8/3, 2011 at 22:59 Comment(1)
Why this is accepted answer: See "Important notes:" in this answer: https://mcmap.net/q/427726/-window-resize-is-not-working-in-chrome-and-operaTartar

© 2022 - 2024 — McMap. All rights reserved.