parent.opener in several levels.

S

Sandman

I have a site that make use of popup windows (on demand, i.e. when one clicks
on a link) to open up comments to texts in and such. It works great, but I have
a problem.

I have a small javascript that I use when I want to open a link in the "main"
window which looks like this:

function quicklink(what){
parent.opener.location=what;
}

This one works great, but sometimes, my popup window opens a popup window (may
sound weird to do, but there are occasions where it's quite logical) and using
quicklink() in this third window will open the link the the second, popup
window when I really would want to open it in the first, main window.

Is there are way to handle this, regardless of number of levels of opened
windows?
 
I

Ivo

"Sandman"wrote
I have a site that make use of popup windows (on demand, i.e. when one clicks
on a link) to open up comments to texts in and such. It works great, but I have
a problem.

I have a small javascript that I use when I want to open a link in the "main"
window which looks like this:

function quicklink(what){
parent.opener.location=what;
}

This one works great, but sometimes, my popup window opens a popup window (may
sound weird to do, but there are occasions where it's quite logical) and using
quicklink() in this third window will open the link the the second, popup
window when I really would want to open it in the first, main window.

Is there are way to handle this, regardless of number of levels of opened
windows?
You 're npot making it very easy on yourself or your users, I guess you
realize that already. What you can do is name the original window, like so:

window.name='mainwindow';

then have the function check the chain of openers for that name, like so:

var el=parent.opener;
while( el.opener && el.name !== 'mainwindow'' ) el=el.opener;
el.location=what;

HTH
Ivo
 
M

Mick White

Sandman said:
I have a site that make use of popup windows (on demand, i.e. when one clicks
on a link) to open up comments to texts in and such. It works great, but I have
a problem.

I have a small javascript that I use when I want to open a link in the "main"
window which looks like this:

function quicklink(what){
parent.opener.location=what;
}

Why "parent" ?
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top