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.
Snap layouts To optimize your screen space and your productivity, hover over a window's maximize button or select a window and press Win+Z, then choose a snap layout. Use Snap to arrange all your open windows using the mouse, keyboard, or the Snap Assist feature.
You can do this by pressing Alt+Tab until that window is active or clicking the associated taskbar button. After you've got the window active, Shift+right-click the taskbar button (because just right-clicking will open the app's jumplist instead) and choose the “Move” command from the context menu.
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");
JavaScript window.open accepts lots of parameters. To your particular case, top and left should suffice.
See the working Fiddle Example!
The Syntax
window.open([URL], [Window Name], [Feature List], [Replace]);
The Feature list
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With