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 the right edge of the opener window.
Here are the requirements:
- Must work in IE8.
- Cannot modify the code in the opener window.
- The opened window should be completely visible (See the X in the upper-right hand corner)
I was able to find a solution that gets the correct width and height (with the scroll bars) of a IE8 window. It involves moving the window and checking it's value, but when I run window.opener.moveTo() it moves the frame instead of the actual window and thus doesn't record the correct values.
Here is the code I am currently using:
function moveAway()
{
//Array Style
var main = getWindowSize(window.opener)
var child = getWindowSize(window)
//How to move
var topAvail = main.top;
var bottomAvail = window.opener.screen.availHeight - main.bottom;
var leftAvail = main.left;
var rightAvail = window.opener.screen.availWidth - main.right;
var choice = Math.max(topAvail,bottomAvail,leftAvail,rightAvail)
if(choice == rightAvail)
{
window.moveTo(main.right,main.top)
window.resizeTo(rightAvail,main.bottom)
}else if(choice == bottomAvail)
{
window.moveTo(main.left,main.bottom)
window.resizeTo(window.opener.document.body.clientWidth,bottomAvail-36)
} else if(choice == leftAvail)
{
window.moveTo(0,main.top)
window.resizeTo(leftAvail,main.bottom)
} else if(choice == topAvail)
{
window.moveTo(main.left,0)
window.resizeTo(main.right,topAvail)
}
//return "item\ttop\tleft\tbottom\tright\nmain\t" + main.join("\t") + "\nchild\t" + child.join("\t")
}
function getWindowSize(windowObj) {
var wW, wH;
var wT = windowObj.screenTop;
var wL = windowObj.screenLeft;
if (windowObj.outerWidth) {
wW = windowObj.outerWidth;
wH = windowObj.outerHeight;
} else {
var cW = windowObj.document.body.offsetWidth;
var cH = windowObj.document.body.offsetHeight;
windowObj.resizeTo(500,500);
var barsW = 500 - windowObj.document.body.offsetWidth;
var barsH = 500 - windowObj.document.body.offsetHeight;
wW = barsW + cW;
wH = barsH + cH;
windowObj.resizeTo(wW,wH);
}
return { right: wW, bottom: wH, top : wT, left : wL };
}