English 中文(简体)
窗口在屏幕上的位置
原标题:Position a Window On Screen

是否有办法将窗口与 jQuery 一起打开的位置定位到屏幕的右上角?

这就是我现在的代码:

$(document).ready(function() {
    $("#dirs a").click(function() {
        // opens in new window
        window.open(this.href, "customWindow", "width=960, height=1040");
        return false;
    });
});

我希望它能在屏幕右上角打开, 类似在Vista 或更高处的 Windows Aero 折叠“ 被困” 。 是否有办法做到这一点?

顺便说一句,这是一个简单的页面,只有我才能使用,我只用在1920x1080年的Chrome监视器上,所以它不需要任何花哨的东西来适应不同的浏览器或屏幕尺寸。

最佳回答

如果他想在右上方,他需要这个吗?

window.open(this.href, "customWindow", "width=960, height=1040, top=0, left=960");
问题回答

JavaScript 窗口. open 接受很多参数。 对于您的特殊案例, 顶端和左侧应该足够 。

见工作"http://jsfiddle.net/zuul/jB6AY/" rel="noreferrer" > fiddle example!

<强> 语法

window.open([URL], [Window Name], [Feature List], [Replace]);

<强 > < 功能列表

""https://i.sstatic.net/puu8x.jpg" alt="此处输入图像描述"/ >

适合您需要的工作示例

<script type="text/javascript">
<!--
function popup(url) 
{
 var width  = 960;
 var height = 1040;
 var left   = screen.width - 960;
 var top    = 0;
 var params =  width= +width+ , height= +height;
 params +=  , top= +top+ , left= +left;
 params +=  , directories=no ;
 params +=  , location=no ;
 params +=  , menubar=no ;
 params +=  , resizable=no ;
 params +=  , scrollbars=no ;
 params +=  , status=no ;
 params +=  , toolbar=no ;
 newwin=window.open(url, customWindow , params);
 if (window.focus) {newwin.focus()}
 return false;
}
// -->
</script>

<a href="javascript: void(0)" 
   onclick="popup( popup.html )">Top Right popup window</a>

Note: This will calculate the screen width to set the left properly.

考虑到您使用的是高高的窗口, 通常屏幕大于高...

window.open(this.href, "customWindow", "width=960, height=1040, top=0, left=0");

其他窗口属性 :

Property         Default value   Description
width            auto            specifies width of the new window in pixels
height           auto            height of the window in pixels
top              auto            specifies window position
left             auto            specifies window position
directories      no              should the directories bar be shown? (Links bar)
location         no              specifies the presence of the location bar
resizable        no              specifies whether the window can be resized.
menubar          no              specifies the presence of the menu bar
toolbar          no              specifies the presence of the toolbar
scrollbars       no              specifies the presence of the scrollbars
status           no              specifies the presence of the statusbar

这是对的。 您需要先计算屏幕的宽度 。

var leftPos = screen.width - 960;
window.open(this.href, "customWindow", "width=960, height=1040, top=40, left="+leftPos+");
$("#dirs a").click(function(e) {
    e.preventDefault();
    var popupWidth = 960;
    var leftPos = screen.width - popupWidth;

    window.open(this.href, "customWindow", "width=" + popupWidth + ", height=1040, top=0, left=" + leftPos);
});

这里有""http://jsfiddle.net/MpjMX/1/" rel = "nofollow" >example





相关问题
Running jQuery command from modal window to affect main page

I m currently trying to write a jQuery script which opens a modal box then (upon user entry) changes a value on the original page. Currently I ve got the script working on just the page itself (...

Animate Window Resize (Width and Height) C# WPF

I m looking for some help on animating window resize of an open window! Cant seem to figure this one out! I m just using atm. this.Width = 500; Any help would be great! Thanks.

Cant drag and move a WPF Form

I design a WPF form with Window Style=None. So I Cannot see the drag bar in the form. How can I move the Form with WindowStyle=None Property?

Win32 CreateWindow() call hangs in child thread?

I m working on a portability layer for OpenGL (abstracts the glX and wgl stuff for Linux and Windows)... Anyhow, it has a method for creating a Window... If you don t pass in a parent, you get a real ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.