Center a popup window on screen?

前端 未结 18 1105
一整个雨季
一整个雨季 2020-11-22 16:51

How can we center a popup window opened via javascript window.open function on the center of screen variable to the currently selected screen resolution ?

18条回答
  •  醉酒成梦
    2020-11-22 17:36

    My recommendation is to use top location 33% or 25% from remaining space,
    and not 50% as other examples posted here,
    mainly because of the window header,
    which look better and more comfort to the user,

    complete code:

        
    
    
        
    
    
    



    check out this line:
    var top = (screen.height - h) / 4; // for 25% - devide by 4 | for 33% - devide by 3

提交回复
热议问题