当我使用funktion时,它会在屏幕的右上角打开一个新窗口。我希望它在屏幕的中心。我该怎么做?
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" );
}
答案 0 :(得分:2)
试试这段代码:
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 );
}