10

JQuery has an event called resize using which you can add an event handler when the window is resized e.g.

$(window).resize(function () {
// code here
});

What I'd need is to resize the window using a JQuery command; would that be possible?

e.g. $(window).resize(-1, -1); // to decrease/increase the width and height of the window

Thanks

The Light
  • 26,341
  • 62
  • 176
  • 258
  • You should check this out: http://stackoverflow.com/questions/599288/cross-browser-window-resize-event-javascript-jquery – Jason Gennaro Jul 15 '11 at 15:37

2 Answers2

27

Try to use this, its a pure javascript no JQuery involved.

window.resizeTo(width, height);
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
  • thanks. window.resizeBy was what I was after. It's odd it doesn't work with values less than 100 e.g. window.resizeBy(100, 100); – The Light Jul 15 '11 at 16:12
  • I think there is some minimum value for height and width which you can set it to a window. If it helped you can you please accept my answer? – ShankarSangoli Jul 15 '11 at 16:58
  • Note that some browsers sensibly won't allow you to resize the main window, potentially full of tabs with other web pages. But you can resize a window you opened as a popup (i.e. via window.open). – Lambart Dec 18 '14 at 19:58
  • Is it possible to animate this - so that the window appears to expand/shrink rather than just snapping to the new size? – Wayne Feltham Jun 09 '17 at 08:12
-3

sorry looks like that binds an event handler to the "resize" JavaScript event, or trigger that event on an element.

see: http://api.jquery.com/resize/

Kevin Burton
  • 11,676
  • 2
  • 24
  • 37