?
Solved

top.opener doesn't work in Netscape

Posted on 2003-03-04
8
Medium Priority
?
535 Views
Last Modified: 2007-12-19
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>
0
Comment
Question by:jgenyuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 8066434
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" ???

0
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 8066585
Actually, top.opener is one of many correct references to the opener.  Most commonly, it is window.opener, but in the case of a frameset in the popup, top.opener is most accurate.

Try this ... when you open the popup, do this:

   var mypopup = window.open( "mypopup.htm", "mypopup", "width=400,height=300" );

   mypopup.opener = self;



This should set the top.opener attribute for the popup.
0
 

Author Comment

by:jgenyuk
ID: 8066614
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:mikkolsoft
ID: 8066710
"..refer to the window that opened the parent window to this frame..."

so I assume it's the window.parent.opener right?
0
 

Author Comment

by:jgenyuk
ID: 8066746
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 .
0
 
LVL 2

Expert Comment

by:mikkolsoft
ID: 8066801
maybe you just lack a "window" at the front:

window.top.opener

Mikkol
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8066907
in this case, window.parent == top (from within the frame).  but if there are no frames, then window == top == self.
0
 

Author Comment

by:jgenyuk
ID: 8068099
mypopup.opener = self  works fine, thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question