Skip to content Skip to sidebar Skip to footer

Javascript Move Opener Window

I have two windows; one is inside a frameset and the other is opened from the other in a new window (window.open(...)). I am trying to move the left edge of the opened window to th

Solution 1:

How do I get JavaScript to open a popup window on the current monitor deals with positioning popup windows and contains a lot of insight into getting screen and window coordinates and positioning windows

You must beware that many browsers will disallow funny behavior like

  • Off-screen windows
  • windows wider than a screen
  • windows that span multiple screens

With code from my answer on the question mentioned above, you can get started with the following

// Pops a window relative to the current window positionfunctionpopup(url, winName, xOffset, yOffset, width, height) {
    width = width || 100;
    height = height || 100;  
    var x = (window.screenX || window.screenLeft || 0) + (xOffset || 0);
    var y = (window.screenY || window.screenTop || 0) + (yOffset || 0);
    returnwindow.open(url, winName, 'top=' +y+ ',left=' +x + ',width=' + width + ',height='+ height);
}

var size = getWindowSize(window);
var popupWin = popup("http://www.google.com", "popup", size.right -  size.left);

I'm not addressing your concern that the popup window must all be on screen. That is because I don't know what you could possibly do if the main window is full screen.

Pop windows are passé, I know some people want to use it, but the browsers are really fighting against it (by imposing rules that came out of tabbed windows environments). You're swimming against the current here.

Last point, you shouldn't need to move your window, you can just specify top/left and width/height, instead of having a window that moves around after it has been displayed. See my popup function.

Here's a jsfiddle to get you started showing us your problem

Post a Comment for "Javascript Move Opener Window"