10

Is there a way to position a window opened with jQuery to the top right corner of the screen?

This is the code I have right now:

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

And I want it to open in the top right corner of the screen, similar to how it would appear if "snapped" with Windows Aero snap in Vista or higher. Is there a way to make this happen?

By the way, this is a simple page that only I will use, and I will only use it in Chrome on a 1920x1080 monitor, so it doesn't have to have any fancy stuff to adjust for different browsers or screen sizes.

chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this question
|improve this questionchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png

I've only caught 2 fish with you and you've spent <2451> with me:(

I've only caught 2 fish with you and you've spent <2451> with me:(
activechrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png oldestchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png voteschrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
19

If he wants it on the top right doesn't he need this?

window.open(this.href, "customWindow", "width=960, height=1040, top=0, left=960");
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this answer
|improve this answerchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • Oh dang, just adding that left=960 fixed it. Thanks, that's perfect :) – JacobTheDevchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:42chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • 1
    Sorry top should be 0, not 40! Fixed it – nmfordchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:42chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • +1 for an oldie but goodie – nathan hayfieldchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png Dec 22 '12 at 0:14chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
6

JavaScript window.open accepts lots of parameters. To your particular case, top and left should suffice.

See the working Fiddle Example!chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png

The Syntax

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

The Feature list

enter image description herehttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpghttps://i.stack.imgur.com/puu8x.jpg

The working example to fit your needs

<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.

Take into consideration that you are using a window with a large height, usually, screens are larger than taller...

chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this answer
|improve this answerchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • 1
    top and left no longer seem to work. – chovychrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png Aug 24 '16 at 2:12chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
1
window.open(this.href, "customWindow", "width=960, height=1040, top=0, left=0");

Other window properties:

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
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this answer
|improve this answerchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • Thanks for copying my answer – Markochrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:39chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • Doesn't appear to work, at least not in Chrome. EDIT: Works fine in Firefox. Maybe I'll just use that if I don't get a better answer. – JacobTheDevchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:39chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • @Marko - really?! - there is only one correct answer and we posted at the same time – web_bodchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:42chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
1

This is the right one.. You need to calculate the width of the screen first.

var leftPos = screen.width - 960;
window.open(this.href, "customWindow", "width=960, height=1040, top=40, left="+leftPos+");
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this answer
|improve this answerchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
  • "this is a simple page that only I will use, and I will only use it in Chrome on a 1920x1080 monitor" – nmfordchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png May 23 '12 at 21:46chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
1
$("#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);
});

Here's an examplechrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png.

chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
Share a link to this answer
|improve this answerchrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png
chrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png

I've only caught 2 fish with you and you've spent <2451> with me:(

I've only caught 2 fish with you and you've spent <2451> with me:(

By clicking “Post Your Answer”, you agree to our terms of servicechrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png, privacy policychrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png and cookie policychrome-extension://mlmmhhnhndopmpilhdjopmaebnjdpeli/images/BaitClub.png

I've only caught 2 fish with you and you've spent <2451> with me:(

I've only caught 2 fish with you and you've spent <2451> with me:(