Center a popup window on screen?

前端 未结 18 1131
一整个雨季
一整个雨季 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:27

    It works very well in Firefox.
    Just change the top variable to any other name and try again

            var w = 200;
            var h = 200;
            var left = Number((screen.width/2)-(w/2));
            var tops = Number((screen.height/2)-(h/2));
    
    window.open("templates/sales/index.php?go=new_sale", '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+tops+', left='+left);
    

提交回复
热议问题