Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 浏览器窗口中心问题_Javascript_Browser_Window.open - Fatal编程技术网

Javascript 浏览器窗口中心问题

Javascript 浏览器窗口中心问题,javascript,browser,window.open,Javascript,Browser,Window.open,我正在尝试使用以下代码通过表单按钮启动一个居中的浏览器窗口 http://www.bbc.co.uk','testwin','width=400,height=400,left=(screen.availWidth-400)/2,top=(screen.availHeight-400)/2');返回false“> 测试按钮 新浏览器将显示正确的高度和宽度,但“左”和“顶”属性将被忽略,因此窗口将显示为左上角 我是不是太雄心勃勃了?我是否应该使用其他语法,还是应该放弃调用函数(如果可以避免的话,我

我正在尝试使用以下代码通过表单按钮启动一个居中的浏览器窗口

http://www.bbc.co.uk','testwin','width=400,height=400,left=(screen.availWidth-400)/2,top=(screen.availHeight-400)/2');返回false“> 测试按钮

新浏览器将显示正确的高度和宽度,但“左”和“顶”属性将被忽略,因此窗口将显示为左上角

我是不是太雄心勃勃了?我是否应该使用其他语法,还是应该放弃调用函数(如果可以避免的话,我宁愿不要)

我使用的是Firefox 3.0.17(最新版本),但IE7也有同样的效果

蒂亚, 艾伦·哈里斯·里德(Alan Harris Reid)

解释了如何做。但我建议使用浮动Div,因为有弹出窗口拦截器

假设您要打开一个尺寸为200h x 150w的窗口。通过取高度和宽度的一半(分别为100和75),您可以精确定位窗口的中心。然后通过一点数学运算,您可以将窗口居中。下面是如何完成的

<SCRIPT LANGUAGE="JavaScript">
function MyPopUpWin() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var win2 = window.open("filename.htm","Window2","status=no,height=200,width=150,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
win2.focus();
}
</SCRIPT>

函数mypopuwin(){
var iMyWidth;
var iMyHeight;
//屏幕宽度的一半减去新窗口宽度的一半(加上5个像素边框)。
iMyWidth=(window.screen.width/2)-(75+10);
//屏幕高度的一半减去新窗口高度的一半(加上标题栏和状态栏)。
iMyHeight=(window.screen.height/2)-(100+50);
//打开窗户。
var win2=window.open(“filename.htm”,“Window2”,“status=no,height=200,width=150,resizable=yes,left=“+iMyWidth+”,top=“+iMyWidth+”,screenX=“+iMyWidth+”,screenY=“+iMyWidth+”,toolbar=no,menubar=no,scrollbars=no,location=no,directories=no”);
win2.focus();
}
要在HTML中调用此函数,请使用以下命令:

<A HREF="javascript:MyPopUpWin()">This is the link</a>

解释了如何做。但我建议使用浮动Div,因为弹出窗口拦截器

假设您要打开一个尺寸为200h x 150w的窗口。通过取高度和宽度的一半(分别为100和75),您可以精确定位窗口的中心。然后通过一点数学运算,您可以将窗口居中。下面是如何完成的

<SCRIPT LANGUAGE="JavaScript">
function MyPopUpWin() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var win2 = window.open("filename.htm","Window2","status=no,height=200,width=150,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
win2.focus();
}
</SCRIPT>

函数mypopuwin(){
var iMyWidth;
var iMyHeight;
//屏幕宽度的一半减去新窗口宽度的一半(加上5个像素边框)。
iMyWidth=(window.screen.width/2)-(75+10);
//屏幕高度的一半减去新窗口高度的一半(加上标题栏和状态栏)。
iMyHeight=(window.screen.height/2)-(100+50);
//打开窗户。
var win2=window.open(“filename.htm”,“Window2”,“status=no,height=200,width=150,resizable=yes,left=“+iMyWidth+”,top=“+iMyWidth+”,screenX=“+iMyWidth+”,screenY=“+iMyWidth+”,toolbar=no,menubar=no,scrollbars=no,location=no,directories=no”);
win2.focus();
}
要在HTML中调用此函数,请使用以下命令:

<A HREF="javascript:MyPopUpWin()">This is the link</a>


想展示一些代码吗?为了得到好的答案这会很有帮助。事实上,他确实展示了一些代码…只是Stack Overflow去掉了它。这是他的原始帖子,没有去掉:想展示一些代码吗?为了得到好的答案这会很有帮助。实际上,他展示了一些代码…只是Stack Overflow去掉了它。这s是他的原始帖子,没有删节:这很好。遗憾的是,它不能作为内联onclick命令工作,但我认为函数在长期内更灵活。谢谢,Alan,这很好。遗憾的是,它不能作为内联onclick命令工作,但我认为函数在长期内更灵活。谢谢,Alan