【问题标题】:How to position a pop up to be in the top right part of the screen如何将弹出窗口定位在屏幕的右上角
【发布时间】:2011-03-10 20:18:18
【问题描述】:

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

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

【问题讨论】:

    标签: javascript browser popup resize window


    【解决方案1】:
    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");
    

    【讨论】:

      【解决方案2】:

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

      基本上,如果您想要解析变量或数学,它们必须在字符串之外。

      【讨论】:

        猜你喜欢
        • 2013-04-22
        • 1970-01-01
        • 1970-01-01
        • 2011-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-03
        • 2022-08-03
        相关资源
        最近更新 更多