0

I want to resize my safari browser window to match the height of a div with id 'po'. I have the following javascript:

    var divHeight = document.getElementById('po').offsetHeight;
    console.log(divHeight);
    divHeight = divHeight + 30;
    var y = parseInt(divHeight,10);
    var w=window.innerWidth;
    window.resizeTo(w,y);
    console.log(divHeight);

The output of the console is:

83
113

But the window gets resized to an actual inner height of only 30! Why isn't the window resizing correctly? If I measure the div (it contains a table), the height of the div is indeed 83. So why won't the window size match? How to fix it?

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190
  • Is it because you are logging `divHeight` after adding 30 to it? If you are looking for the window height, you might want to use something like: `var windowSize = window.innerHeight;` and log `windowSize` – Craighead Jan 17 '14 at 19:22
  • I don't understand why logging divHeight should affect window.resizeTo. Can you explain? – Rahul Iyer Jan 17 '14 at 19:26
  • I removed logging, but the window still resizes to the incorrect height. I don't think logging has anything to do with it. – Rahul Iyer Jan 17 '14 at 19:27
  • Sorry, I was just pointing out that you were likely logging the wrong thing if you were looking at it from a troubleshooting standpoint. Do you have any other supporting code or a Fiddle by chance? – Craighead Jan 17 '14 at 19:29
  • I don't know what a fiddle is. This is the first time I'm really coding with javascript. I normally code in objective-c. The remaining supporting code is irrelevant. This is the only code that changes the window size. – Rahul Iyer Jan 17 '14 at 19:36

1 Answers1

1

The problem was in my calculation and misunderstanding how window.resizeTo() works.

The size that window.resizeTo() sizes to includes the chrome(scrollbars, address bar,favourites bar, etc)! Once I added some "padding" to include that, it worked as expected.

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190