0
$("#show > div").click(function() {
    var a = $(this).html();
    alert (a); // 860
    window.resizeTo(a + "px", 450 + "px");
});

The above is the accepted answer from this SO post.

But doesn't work. On click - nothing happens !

Community
  • 1
  • 1
qadenza
  • 9,025
  • 18
  • 73
  • 126
  • As also pointed out in the same post, it doesn't work across all browsers. Which browser did you use to test? And does your console (if you are using Chrome/Firefox) display any errors? – JofryHS Jul 28 '14 at 10:31
  • First of all, I don't think you should be appending the `px`s. Secondly, [have a look here](http://stackoverflow.com/questions/7602078/javascripts-window-resizeto-isnt-working) – Raul Rene Jul 28 '14 at 10:32
  • @JofryHS, tested in Chrome and Firefox. Console is empty. – qadenza Jul 28 '14 at 10:34

1 Answers1

1

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.

You can see in w3school an example for the resizeTo function, used for resizing a popup: http://www.w3schools.com/jsref/met_win_resizeto.asp

function openWin() {
    myWindow = window.open("", "", "width=100, height=100");  // Opens a new window
}

function resizeWin() {
    myWindow.resizeTo(250, 250);                             // Resizes the new window
    myWindow.focus();                                        // Sets focus to the new window
}
griffon vulture
  • 6,594
  • 6
  • 36
  • 57