我想要做的是更改窗口的大小并在其旁边创建一个窗口,使它们完全相邻。从这个意义上讲,我需要将新窗口定位到屏幕的右上角,我这样做的方式不起作用(代码如下),我需要帮助:))
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");
}
答案 0 :(得分:7)
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 :(得分: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");
基本上,如果你想要解析变量或数学,它们必须在字符串之外。