By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

only executes in child window

P: n/a
I have a parent window where I open a child window.

In that child window I have some js that creates a row in the parent
window, it looks like:

if ( self.opener.document.update )
{
var actTable =
self.opener.document.getElementById("Action_Table" );
myTR = self.opener.document.createElement("TR");
myTD = self.opener.document.createElement("TD"); myA =
self.opener.document.createElement("A"); myA.href =
"javascript:void(null);"; myA.onclick = function (evt) {
alert('mike'); } myA.className = "greenlink";
myTEXT =
self.opener.document.createTextNode('click'); myA.appendChild(myTEXT);
myTD.appendChild(myA);
myTR.appendChild(myTD);
var lastRow = actTable.rows[actTable.rows.length-1];
lastRow.parentNode.appendChild(myTR);
}

This js creates the row in the parent window ok, but I only get the
alert message when the child window is up. After I close the child
window I get no alert.

Mike

Oct 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"mike" <hi****@charter.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a parent window where I open a child window.

In that child window I have some js that creates a row in the parent
window, it looks like:

if ( self.opener.document.update )
{
var actTable =
self.opener.document.getElementById("Action_Table" );
myTR = self.opener.document.createElement("TR");
myTD = self.opener.document.createElement("TD"); myA =
self.opener.document.createElement("A"); myA.href =
"javascript:void(null);"; myA.onclick = function (evt) {
alert('mike'); } myA.className = "greenlink";
myTEXT =
self.opener.document.createTextNode('click'); myA.appendChild(myTEXT);
myTD.appendChild(myA);
myTR.appendChild(myTD);
var lastRow = actTable.rows[actTable.rows.length-1];
lastRow.parentNode.appendChild(myTR);
}

This js creates the row in the parent window ok, but I only get the
alert message when the child window is up. After I close the child
window I get no alert.

When the child window is closed the js included in the file will not be
exectuted.
Oct 12 '05 #2

P: n/a
I was thinking that:

myA.onclick = function (evt) { alert('mike'); }

was associated with the tag now in the parent window.

So, If I wanted to do this correctly, how would it be done then?

Mike

Oct 12 '05 #3

P: n/a

"mike" <hi****@charter.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I was thinking that:

myA.onclick = function (evt) { alert('mike'); }

was associated with the tag now in the parent window.

So, If I wanted to do this correctly, how would it be done then?


what is it you need to do ? You cant have a non existent window updating
its parent.
Oct 12 '05 #4

P: n/a
I have a parent window with some "parent data" and it contains the
"keys" to child data.

Consider the following root data:
parent_id title
1 first
2 second
3 third

Consider the following child data:
parent_id child_id child_title
1 1 first action
1 2 second action
2 1 another first action
2 2 another second action

The user updates the root data and sometimes need to create a new
child. So the functionality exists to open a new window and when the
new window is opened a new child is created in the db. The javascript
in the child window creates a new row in the parent window with a
"link", i.e. the onclick function we are talking about. That link
contains the parent_id and child_id so it can be updated again if the
user needs to.

The alternative would be to "refresh" the parent window after the child
is created, but that takes time and it is faster to just create the row
in the parent window dynamically, with a link in case the user needs to
re-update the child data again.

What you are saying is the function assocaited with the onclick event
remains in the child window even though I can see the link in the
parent window.

I hope that makes some sence. Appreciate your help.

Mike

Oct 12 '05 #5

P: n/a
Well I just placed the code in the parent window and made a call to it
from the child using:

self.opener.mynewfunction(par_id,chd_id);

works fine ...

Oct 12 '05 #6

P: n/a
mike wrote in news:11**********************@g43g2000cwa.googlegr oups.com
in comp.lang.javascript:
myA = self.opener.document.createElement("A");
myA.href = "javascript:void(null);";
myA.onclick = function(evt) { alert('mike'); }
This js creates the row in the parent window ok, but I only get the
alert message when the child window is up. After I close the child
window I get no alert.


The alert() is bound to the child window object which has been
closed, try:

myA.onclick = function(evt) { self.opener.alert('mike'); }

instead.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Oct 12 '05 #7

P: n/a
mike wrote:
I was thinking that:

myA.onclick = function (evt) { alert('mike'); }

was associated with the tag now in the parent window.
In javascript functions are objects, and evaluating a function
expression causes a function object to be created and a reference to
that function to be the result of the expression (it is the reference to
the (anonymous) function object that is assigned to the event handler).
That function object must reside somewhere and as it was created by code
in the pop-up it is likely to reside in memory associated with the
pop-up, and so became unavailable when the pop-up closed.
So, If I wanted to do this correctly, how would it be
done then?


There is no correct way of doing this. ECMA 262 assumes a single
execution environment, but multiple windows/frames represent multiple
execution environments, and the spec has nothing to say about how they
should interact.

What you want to do is arrange that the function object that is created
and assigned as the event handler is created in the opener rather than
in the pop-up. You should be able to do this by creating a function in
the opener that crates the function you want locally and returns a
reference to that function to the pop-up code.

I could show you how to do that in several ways but I observe that you
are already crating elements with -
self.opener.document.createElement("TD"); - so maybe all of the table
crating code should be moved into a function in the opener and just
called from the pop-up.

Pop-ups are of course terribly unreliable theses days so it probably
isn't sensible to be going in this direction at all, as the result will
be a system that is needlessly unreliable by design.

Richard.
Oct 13 '05 #8

P: n/a
Crap ...

I hated when you said this:
Pop-ups are of course terribly unreliable theses days so it probably
isn't sensible to be going in this direction at all, as the result will
be a system that is needlessly unreliable by design.


I am experiencing some inconsistency. See the new item "IE has to
close".

Mike

Oct 14 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.