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.valu e = ' <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>
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.valu
+ '</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>Add a link to currently open page.</td></tr>
<tr><td><input type=button name=add_image value="Add Image"
onclick="image_onclick();"
<td>Add a picture from currently open page.</td></tr>
</table>
<input type=hidden name="add">
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
so I assume it's the window.parent.opener right?
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
window.top.opener
Mikkol
in this case, window.parent == top (from within the frame). but if there are no frames, then window == top == self.
ASKER
mypopup.opener = self works fine, thanks
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" ???