<ni**********@webinfo.fi> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Okay thanks for you help. This is what I'm using:
I may be wrong here (I'm working from memory and I've got a lousy memory).
The first problem is that you need to know the names of your windows or have
a reference to them to do this - so the AAA function would need to know the
name or have a reference of the BBB window and vice versa. Since you're
window names are dynamically generated this will be harder than it would be
with static name - but it's not so difficult with references. Also you
should really get into the habit of using the var keyword for local
variables... you'll thank me later.
For now I'm just going to write a variable in the main page global scope
called "AAAWindowName" and "BBBWindowName". But there are definately many,
many other ways to do this.
Are you actually using the generated name "page" + id? If not there's
really no need to eval this just to set the variable. I'm going to assume
that you're NOT and can just use the window name. For this purpose I'll
call it "page" + id just because it feels odd to have an numeric identifier
for this. Consider having your function return a reference to the new
window and use that instead.
There's no real need, from the code you have here, to have two functions -
the only difference is the width and height and they could be passed as
arguments to a generic "open window" funciton.
But let's start simply. Function AAA might look like this:
function AAA(URL) {
// First Generate the Window Name
var WinName = "page" + new Date().getTime();
// Open the window, assign a reference to it to a local variable
var CurWindow = window.open(URL, WinName, ' ... window stuff...);
// Add a reference to the window the main page.
AAAWindow = CurWindow;
// Now adjust focus, if needed, of the other window
// First we must check to see if the other variable has actually
been defined
if ( typeof BBBWindow == 'object' ) {
// Give the BBBWindow focus via the stored reference
BBBWindow.focus();
};
// Now give THIS window focus to make sure it's still on top
CurWindow.focus();
// Now return a reference to the window for use in the rest of the
application:
// If you need the name instead return "WinName" and use it.
return CurWindow;
};
That's good but let's make it more generic.
From what you've described I'm just not seeing the need to generate names of
the windows... let's, for a moment say, you don't need to. Let's also say
that you want to make this general enough to use with any number of windows
(I won't get into the interface issues there... but they definitely exist).
So, instead of single "AAAWindow" and "BBBWindow" variables we'll create a
hash map of window references.
// Create a new global object (our hash map)
PopupGroup = new Object();
// Create a generic createPopup function
function createPopup(Name, URL, height, width) {
// Open the window, assign a reference to it to a local variable
var CurWindow = window.open(URL, Name, ' ... window stuff - include
height and width...);
// Add a reference to the window to the hash map.
// You could also do this in the line above but I'm being methodical
here
PopupGroup[Name] = CurWindow;
// Now bring ALL popups in the group to the front
for ( Popup in PopupGroup ) {
PopupGroup[Popup].focus();
};
// Now give the newly created popup focus to make sure it's still on
top
CurWindow.focus();
// Now return a reference to the popup for use in the rest of the
application:
return CurWindow;
};
To open your two windows here you might call the function like this:
createPopup("AAA", URL, 482, 548);
createPopup("BBB", URL, 210, 280);
To then access them in the rest of the application you could use:
PopupGroup["AAA"] or PopupGroup["BBB"]
For example:
PopupGroup["AAA"].document.write("Hello!");
Personally I always lean towards organizing things like this... it makes
life a lot simpler (I think).
Hope this helps,
Jim Davis