Link to home
Start Free TrialLog in
Avatar of jgenyuk
jgenyuk

asked on

top.opener doesn't work in Netscape

Hello,

I have a window that opens another window with two frames. From one of
the frames I'm trying to get elements of the opening window. This code
works well in IE but not in Netscape 4.79. The alert in link_onclick
never shows up, and image_onclick gives an error "top.opener has no
properties".

What am I doing wrong? Thanks.

Julia


<script>
function link_onclick() {
    if ( top.opener ) {
    alert("link_onclick");
        var loc = top.opener.location.href;
        var tit = top.opener.document.title;
        document.add_form.add.value =  ' <A HREF="' + loc + '">' + tit
+ '</A> ';
    }
    document.add_form.submit();
}

function image_onclick() {
   with ( top.opener.document ) {

***more code***
   }
}
</script>


This is the relevant HTML:

<form name="add_form" method=post action="WBedit.pl">
<p>
<table cellspacing=5>
<tr><td><input type=button name=add_link value="Add Link"
onclick="link_onclick();"></td>
<td>Add a link to currently open page.</td></tr>
<tr><td><input type=button name=add_image value="Add Image"
onclick="image_onclick();"></td>
<td>Add a picture from currently open page.</td></tr>
</table>
<input type=hidden name="add">
</form>
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

I wonder why top.opener should ever work.

Top is the root of all windows.
opener is one associated window to the actual window.

That top.opener work is only a error tolerance and you get either top or opener.

Or did you name a frame or window "opener" ???

ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jgenyuk
jgenyuk

ASKER

No, I didn't name anything "opener". That was supposed to refer to the window that opened the  parent window to this frame. Is there another way to do this? Just "opener" doesn't work.
"..refer to the window that opened the parent window to this frame..."

so I assume it's the window.parent.opener right?
Avatar of jgenyuk

ASKER

It  is but I'd like to go with "top" because I might add more nested frames later on. I'll try mypopup.opener = self .
maybe you just lack a "window" at the front:

window.top.opener

Mikkol
in this case, window.parent == top (from within the frame).  but if there are no frames, then window == top == self.
Avatar of jgenyuk

ASKER

mypopup.opener = self  works fine, thanks