25

I would like to be able to resize the browser window with JavaScript. I don't want to use jQuery, and the smaller the code the better, but it has to work in all of the major browsers including Chrome.

Any solutions?

Thanks for the help!

P.S. The tags that this question was tagged with should be combined but I don't know how.

browser -----------same as--> webbrowser

cross-browser----same as--> browser compatibility

2
  • Why don't you want to use jQuery (or some other useful framework)? Commented Sep 17, 2011 at 2:33
  • 1
    @Eddie This is just a very small task, and I'd rather not include a very large library. Commented Sep 17, 2011 at 2:39

3 Answers 3

21

window.resizeTo( width, height );

The problem you may face is modern day browsers can prevent you in the settings to not be able to resize the window. There is no way around that.

Chrome will not allow it. Won't Fix Bug

IE is based on security zones

Sign up to request clarification or add additional context in comments.

3 Comments

Because modern day browsers block it. Chrome won't fix
I love how the chrome thread breaks down to flaming like a bunch of children throwing tantrums.
The article says resizeTo is DOM0: general convention not in any standard.
11

The fact is that Chrome, Firefox and newer IEs doesn't allow resize of tabbed windows and windows not opened by window.open() (Chrome at least).

But for popups it's doable for the most part, unless the security setting in the browser blocks that functionality. However using window.resizeTo() is complicated. Use window.resizeBy() instead.

Chrome has a bug getting the size of a popup window to soon so you have to work around that.

if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
    var t = setTimeout("resize()", 200);
else
    resize();

function resize() {
    var innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    var innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    var targetWidth = 800;
    var targetHeight = 600;
    window.resizeBy(targetWidth-innerWidth, targetHeight-innerHeight);
}

Comments

6

There is no way for a web page to resize the main browser window in Chrome. JavaScript code is only permitted to resize popup windows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.