Javascript 打开新窗口

Javascript 打开新窗口,javascript,Javascript,我必须使用2个按钮打开2个新窗口: <input id="Corner" type="button" value="Corner" onclick="corner()"/> <input id="Center" type="button" value="Center" onclick="center()"/> 首先,为什么heigh不能获得屏幕高度() 中间按钮应在中间打开一个新窗口,然后在所有4个方向上扩展窗口以覆盖所有屏幕。我不知道怎么做 function cent

我必须使用2个按钮打开2个新窗口:

<input id="Corner" type="button" value="Corner" onclick="corner()"/>
<input id="Center" type="button" value="Center" onclick="center()"/>
首先,为什么heigh不能获得屏幕高度()

中间按钮应在中间打开一个新窗口,然后在所有4个方向上扩展窗口以覆盖所有屏幕。我不知道怎么做

function center() {
//...?
}

window.open
没有用于动画的本机功能。要实现这一点,您需要一些其他javascript代码,如或。不过,我将在下面讨论其他问题

如果使用纯javascript,则可以通过对象访问屏幕尺寸:

[Window.screen]返回对与窗口关联的screen对象的引用。 屏幕对象是用于检查屏幕属性的特殊对象 正在渲染当前窗口的屏幕

像这样:


此外,要包含实际值,而不仅仅是一个写有“screen.height”的字符串,请在
窗口中连接这些值。打开
字符串:

函数角(){
打开窗户(
"https://www.facebook.com/",
“新”,
“height=“+screen.height+”,width=“+screen.width
);
}

您的
角落
功能应该是:

function corner() {
    window.open("https://www.facebook.com/", "New", "height=" + screen.height + ",width=" + screen.width);
}
以及您的
中心
功能:

function corner() {
window.open("https://www.facebook.com/", "New", "height=screen.height(),width=screen.width()");
}
function center(w,h) {
    var left = screen.width/2 - w/2;
    var top = screen.height/2 - h/2;
    window.open("https://www.facebook.com/", "New", "left=" + left + ", top=" + (top-52) + ", width=" + w + ", height=" + h);
}
为了使新窗口居中,它需要具有特定的宽度和高度。您可以将这些值传递到html中的函数中

<input id="Center" type="button" value="Center" onclick="center(1000,500)" />


请将你的
center()
函数也包括在内。@showdev我不知道怎么做,center()是空的。你真的想要一些动画吗?@nevermind实际上这是一个无用的迟钝类练习。。。甚至不确定是否可以像动画一样展开窗口。PS:由于懒惰的老师,没有给学生提供文档。您的
函数应该是
窗口。打开(“https://www.facebook.com/“,”新建“,”高度=“+screen.height+”,宽度=“+screen.width”)