如何将弹出窗口放置在屏幕的右上角

发布于 2024-09-08 02:11:47 字数 463 浏览 2 评论 0原文

我想要做的是更改窗口的大小并在其旁边创建一个窗口,以便它们彼此完全相邻。从这个意义上说,我需要将新窗口定位到屏幕的右上角,我这样做的方式不起作用(代码如下),我需要帮助:)

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"); 
}

What I want to do is to change the size of a window and create a window next to it so they are exactly next to each other. In that sense, I need to position to the new window to the top right part of the screen, the way I am doing it is not working (code is below), I need help :)

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"); 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无需解释 2024-09-15 02:11:47
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");
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");
虫児飞 2024-09-15 02:11:47

我还没有测试过实际的窗口大小数学;不确定这是否正确。但您遇到的第一个明显的问题是将变量嵌入到对 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");

基本上,如果您希望变量或数学得到解析,它们必须位于字符串之外。

I haven't tested out the actual window size math; not sure if that's correct. But the first, obvious, problem you have is embedding the variables into the call to window.open. Try changing

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

to

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

Basically, if you want the variables or the math to get resolved, they have to be outside the string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文