简体   繁体   中英

Why doesn't the window resize to the correct height?

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?

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.

Guessing this link will help you. why dont you have a look at this page.... Javascript's `window.resizeTo` isn't working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM