2010-07-01 241 views
2

我想要做的是更改窗口的大小並在窗口旁邊創建一個窗口,以使它們緊密相鄰。在這個意義上,我需要定位到新的窗口到屏幕的右上部分,我做的方式是不工作(代碼如下),我需要幫助:)如何將彈出窗口放置在屏幕的右上角

function() { 
    var viewportwidth = document.documentElement.clientWidth; 
    var viewportheight = document.documentElement.clientHeight; 
    window.resizeBy(-300,0); 
    window.open("something.htm", 
    "mywindow", 
    "width=300, 
    height=viewportheight, 
    left=(viewportwidth - 300), 
    top=0, 
    screenX=0, 
    screenY=0"); 
} 

回答

6
var viewportwidth = document.documentElement.clientWidth; 
var viewportheight = document.documentElement.clientHeight; 
window.resizeBy(-300,0); 
window.moveTo(0,0); 

window.open("http://google.com", 
      "mywindow", 
      "width=300,left="+(viewportwidth-300)+",top=0"); 
1

我的天堂沒有測試出實際的窗口大小數學;不知道這是否正確。但是,第一個顯而易見的問題是將變量嵌入到window.open的調用中。嘗試改變

window.open("something.htm", "mywindow", 
"width=300, height=viewportheight, left=(viewportwidth - 300), top=0, screenX=0, screenY=0"); 

window.open("something.htm", "mywindow", 
"width=300, height=" + viewportheight + ", left=" + (viewportwidth - 300) + ", top=0, screenX=0, screenY=0"); 

基本上,如果你想要的變量或算算得到解決,他們必須在字符串之外。

相關問題