2010-07-01 151 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"); 

基本上,如果你想要的变量或算算得到解决,他们必须在字符串之外。

相关问题