Disable Browser Window Resize

前端 未结 2 1892
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 05:52

For starters... I have no sinister intention of subjecting users to popups or anything like that. I simply want to prevent a user from resizing the browser window of a webpa

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 06:02

    You can first determine a definite size.

    var size = [window.width,window.height];  //public variable
    

    Then do this:

    $(window).resize(function(){
        window.resizeTo(size[0],size[1]);
    });
    

    Demo: http://jsfiddle.net/DerekL/xeway917/


    Q: Won't this cause an infinite loop of resizing? - user1147171

    Nice question. This will not cause an infinite loop of resizing. The W3C specification states that resize event must be dispatched only when a document view has been resized. When the resizeTo function try to execute the second time, the window will have the exact same dimension as it just set, and thus the browser will not fire the resize event because the dimensions have not been changed.

提交回复
热议问题