2014-10-07 221 views
0

我一直在使用2个按钮,打开2个新的窗口:打开新窗口

<input id="Corner" type="button" value="Corner" onclick="corner()"/> 
<input id="Center" type="button" value="Center" onclick="center()"/> 

角窗应该从左上角打开一个新的窗口,在整个屏幕扩大,这是我不能正常工作的功能:

function corner() { 
window.open("https://www.facebook.com/", "New", "height=screen.height(),width=screen.width()"); 
} 

首先为什么不高得到screen.height()?

中心按钮应该在中心打开一个新窗口,然后在所有4个方向上展开窗口以覆盖所有屏幕。我不知道如何做到这一点。

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

请提供您的'中心()'函数了。 – showdev 2014-10-07 21:25:03

+0

@showdev我不知道如何做到这一点,中心()是空的 – Alpha2k 2014-10-07 21:26:21

+1

你真的想要某种动画吗? – sinisake 2014-10-07 21:27:33

回答

1

window.open对动画没有本机功能。您需要使用其他一些JavaScript代码,例如thisthese才能实现此目的。不过,我会解决下面的其他问题。

如果使用纯JavaScript,可以通过window.screen对象访问屏幕尺寸:

[Window.screen]返回到与所述窗口相关联的屏幕对象的引用。 屏幕对象是一个特殊对象,用于检查正在呈现当前窗口的屏幕 的属性。

像这样:

screen.height (or window.screen.height)
screen.width (or window.screen.width)

此外,包括实际的价值,而不是只是一个字符串,上面写着 “screen.height”,串联的值window.open字符串:

function corner() { 
    window.open(
     "https://www.facebook.com/", 
     "New", 
     "height=" + screen.height + ",width=" + screen.width 
    ); 
} 

WORKING EXAMPLE

0

corner功能应该是:

function corner() { 
    window.open("https://www.facebook.com/", "New", "height=" + screen.height + ",width=" + screen.width); 
} 

和你center功能:

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)" /> 

FIDDLE