Cross window scripting

How can I refer to a window by name only?

i.e. :

The main window of the site is called "mainwindow".

When I open a popup from mainwindow called "popup1" I can refer to "mainwindow" using:


When I open a popup from "popup1" called "popup2", how can I refer to "mainwindow" from "popup2"?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just to clarify, are you trying to determine the origination of "popup2", via code? Eg:

under_dogAuthor Commented:
Basically yes ...

One of the things I need to do is redirect the user to another page in MainWindow based on an onclick action in popup2.

From Popup1 I can simply do:

window.opener.location = 'redirecthere.php';

so my question is how can I redirect MainWindow from Popup2? Once I have that working I can adapt it for my other needs :p
Can't say I have ever had to do this, but here's something you could try, it's a shot in the dark....

Option 1:
Determine the name of the parent window
Determine the name of that determined name
loop through this until you find an absolute parent

Option 2:
Main window opens newpage as: mypage.php?parent=mainwindow
this alters the javascript of that open popup to include the parent name
keep passing the parent name up so that when it's needed to be determined, no calculations are required

Option 2 should work (if you have server side scripting on your webpages)
Option 1 I'm not sure will work or not, as I tend to avoid popups where I can, and instead use floating <div> elements

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

under_dogAuthor Commented:
Oh I think you misunderstand ... I _know_ the name of the window I want to redirect ... I'm just not sure of the syntax to reference it ... I've tried:


and everything else I could think of, but nothing works :p
Ah ok, try this:

function changeURL(winName, newURL) {
  win =, winName);
under_dogAuthor Commented:
hmm ok that does work ... but I also need to get the original href of the mainWindow BEFORE I redirect them ... using your idea gives me a handle to give the window focus and manipulate it later, which is great ... but I need to know what the original page was.

Apologies for the delay in getting back to you, but it's been hell at work and I've only just had some time to test :p
Ah ok, I have no clue how, and IF you can even reference a window to determine it's location...

But if you want to determine the location of the highest point, example:


and you want Popup3 to display the location of Window1, you can use this:


Does that help at all?
under_dogAuthor Commented:
Ok a combination of both of your suggestions and I have come up with something that works:

mainFound = false;
objectName = 'window';
while (mainFound == false) {
  objectName += '.opener'      
  objectNameTest = objectName + '.name';
  if (eval(objectNameTest) == "mainwindow") {
    mainFound = true;


windowHandle = eval(objectName);


I can then use the windowHandle variable to manipulate the top window, and it works regardless of how many other windows are in between!

Thanks for your help guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.