You can make a new function that basically wraps the existing functionality with what you're trying to do.
var WindowDialog = new function() {
this.openedWindows = {};
this.open = function(instanceName) {
var handle = window.open(Array.prototype.splice.call(arguments, 1));
this.openedWindows[instanceName] = handle;
return handle;
};
this.close = function(instanceName) {
if(this.openedWindows[instanceName])
this.openedWindows[instanceName].close();
};
this.closeAll = function() {
for(var dialog in this.openedWindows)
this.openedWindows[dialog].close();
};
};
Sample Usage
WindowDialog.open('windowName', /* arguments you would call in window.open() */);
WindowDialog.open('anotherName', /* ... */);
WindowDialog.open('uniqueWindow', /* ... */);
WindowDialog.open('testingAgain', /* ... */);
WindowDialog.open('finalWindow', /* ... */);
// closes the instance you created with the name 'testingAgain'
WindowDialog.close('testingAgain');
// close all dialogs
WindowDialog.closeAll();