window.resize is not working in chrome and opera
Asked Answered
M

3

14

window.resize is not working in chrome and opera ..how to make it work?

Membership answered 28/2, 2011 at 7:39 Comment(2)
Hey, did you find a better answer, than please share, or accept one of these. THXGreybeard
possible duplicate of The javascript "resizeTo" function not working in Chrome and OperaGreybeard
D
28

There is no window.resize()

...however...

There are:

window.resizeTo(width, height)

window.resizeBy(x, y)

Important notes:

  1. You can't resize a window or tab that wasn’t created by window.open.
  2. You can't resize a window or tab when it’s in a window with more than one tab.
  3. Also, even if you create window by window.open(...) it is not resizable by default ...see 4.
  4. To make window created by window.open() resizable, you must open it with resizable feature

Example of how to create external window with "resizable" feature:

myExternalWindow = window.open("http://myurl.domain", "myWindowName", "resizable");
myExternalWindow.resizeTo(500,500); //resize window to 500x500
myExternalWindow.resizeBy(-100,-100); //make it smaller relatively => to 400x400

PS: There are also browser extensions that allow window resizing... (Chrome)(Mozilla Firefox)

PS2: Chrome extension API - https://developer.chrome.com/extensions/windows

Danelaw answered 4/3, 2016 at 17:5 Comment(1)
I just realized where do people come from with that idea and it's because there is an event (not a method) called "resize" that is fired on window ( developer.mozilla.org/en-US/docs/Web/API/Window/resize_event ) but again, that's not a method of window, it's just an event :)Danelaw
M
4

This is because it is not supported in Opera and Chrome...

http://www.w3schools.com/jsref/met_win_resizeto.asp

UPDATE:

This might help you in finding something specific to what you want...

http://bytes.com/topic/javascript/answers/153185-moveto-resize-firefox

Marita answered 28/2, 2011 at 7:44 Comment(1)
@hema: No, it simply doesn't exist there (or it exists and does nothing). Furthermore, some other browsers have the user option to disable the function, so you can't really rely on it in any browser.Tourer
J
0

Note: There is no public standard that applies to the Window object, but all major browsers support it.

The window.resizeTo() and window.resizeBy() methods are supported in all major browsers, except Opera and Chrome.

refer
Window resizeTo() Method
Window resizeBy() Method

Julio answered 28/2, 2011 at 7:46 Comment(3)
it will work in Opera and chrome in case the window is a popupMembership
The difference is that a popup is opened by your page while the main window is opened by the user. With many tabs, why should your page have the right to change the pagesize for all tabs?Teetotaler
@DavidMårtensson That's a reasoning Microsoft took for IE, but they instead made the function useless only when there are other tabs open.Chopper

© 2022 - 2024 — McMap. All rights reserved.