简体   繁体   中英

How can I center the pop-up window on the screen?

When I use the funktion it opens up a new window up in the right corner of the screen. I want it in the center of the screen. How do I do that?

function f(){
var gid=function(i){return document.getElementById(i);};
var version_id=gid("two").value;
var arch_id=gid("three").value;
if( version_id ==='default' || arch_id === 'default'){return;}
window.open('images/' + version_id + '_' + arch_id + '.jpg', "_blank", "width=200, height=200" );   
}    

Try this code:

function f(){
  var gid=function(i){return document.getElementById(i);};
  var version_id=gid("two").value;
  var arch_id=gid("three").value;
  var width = 200;
  var height = 200;
  var left = (screen.width/2)-(width/2);
  var top = (screen.height/2)-(height/2);
  if( version_id ==='default' || arch_id === 'default'){return;}

  window.open('images/' + version_id + '_' + arch_id + '.jpg', "_blank", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', top='+top+', left='+left );   
} 

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