javascripthtmldomwindow-resizeeel

Why window.resizeTo() function is not resizing window at the smaller then given values in JavaScript


I am building an app using python-eel in chrome mode (Front end : in HTML, CSS & JS). The problem is I use a function which resize the window on resizing the window so that my app content looks good (without extra space & some hidden content.

JavaScript code :-

sideBar.style.display="none";    // Hiding aside bar on startup
function setsize(){
    if (sideBar.style.display != "none"){window.resizeTo(510,600);}    // If aside is shown/open
    else{window.resizeTo(310,600);};    // If aside is hidden
};
function showaside(){    // Function for hiding or unhiding the aside
    if(sideBar.style.display != "none"){
        sideBar.style.display = "none";
    }
    else{
        sideBar.style.display = "block";
    };
setsize();

But the problem is when I start the app, window is resized to 295px x 561px but size which I set is 310px x 600px.

Note : This problem is only occurring in Windows10, when I tried to run my app in Ubuntu (linux), it is working according to my desire.

Please let me know where this problem is occurring, Thanks a lot in advance.


Solution

  • I was facing this problem for a long, but now I have found a way to adjust screen size of python-eel window which not only works in Windows also gives exact size in Linux. Even in which mode you use, such as: chrome, edge etc.

    JavaScript :

    function setsize(){
        var y = 600;
        var x;
        if(sideBar.style.display != "none"){x = 510;}
        else{x = 310};
        
        if(window.innerWidth != x || window.innerHeight != y){
            window.resizeTo(x,y);
            var width = x - window.innerWidth;    //innerWidth is read only
            var height=y - window.innerHeight;    //innerHeight is also read only
            window.resizeTo(x + width, y + height);
        };
    };
    

    This all is just because this JavaScript function resize the python-eel window according to outer width and height this function will adjust the height according to inner width and height.

    I hope this will helpful for you.