2014-10-07 304 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