I have the below js. popUpWindow function is called from a command button click event. Not sure, why child window is not closing.
var loadedWindows = new Array();
//Define window width and height
var screenWidth;
var screenHeight;
var x = screen.width;
var y = screen.height;
var num1 = new Number(x);
var w = num1 - 125;
var num2 = new Number(y);
var h= num2 - 75;
var left = num1;
/**
* Define method to open window keep track of opened child windows.
*/
popUpWindow = function(wndUrl, wndName, wndWidth, wndHeight, sourceID){
var windObj = null;
try
{
//set default width
if(typeof wndWidth == 'undefined') wndWidth=screenWidth;
//set default height
if(typeof wndHeight == 'undefined') wndHeight=screenHeight;
if(document.documentElement.clientWidth < 1090){
windObj = window.open(wndUrl,
//misc options to open a window, again mostly optional
wndName, "left="+left+",top=0,location=0,status=1,scrollbars=yes, resizable=yes,width="+(h-110)+",height="+(h+65));
} else {
windObj = window.open(wndUrl,
//misc options to open a window, again mostly optional
wndName, "left="+left+",top=0,location=0,status=1,scrollbars=yes, resizable=yes,width="+y+",height="+x);
}
loadedWindows[loadedWindows.length] = windObj;
return windObj;
}
catch(ex){
alert('WindowController.popUpWindow: ' + 'Exception occured, message: ' + ex.message);
}
return windObj;
};
/**
* Method to register close event - to close window on close of parent window
*/
function WireEvent(elem,target,func){
if (elem.addEventListener)
elem.addEventListener(target, func, false); //FF
else if (elem.attachEvent){
elem.attachEvent(target, func); //IE
}
}
/**
* method to close all windows
*/
closeAllWindows = function(){
for(var x = 0; x < loadedWindows.length; x++){
try{
loadedWindows[x].close();
}
catch(err) {
alert('WindowController.closeAllWindows: ' +'Exception occured, message: ' + err.message);
}
}
};
WireEvent(window,'onunload',this.closeAllWindows);