473,246 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

only executes in child window

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
8 1597

"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
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

"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Randell D. | last post by:
Folks, I'm working on a contact name/address database whereby a slimed down list is shown in the main window. When a record is selected, the complete record is displayed in a new window via a...
1
by: ian.michel | last post by:
I have a parent window that pushes a new window object onto an Array with the following code : OpenChild() { //totalNumWindowsCreated is global totalNumWindowsCreated =...
2
by: Bostonasian | last post by:
I am trying to append options to dropdown in parent window from option items in child window. In parent window, I have following code: <script language="javascript"> function...
2
by: Jon | last post by:
I am writing an MDI app that uses a document manager class to keep track of opened child windows. I want the user to be able to close a child window, but then re-open the window from the "Window"...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
3
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be...
4
by: Steve Barnett | last post by:
I've created a simple MDI application and have designated the Window menu to keep track of the mdi children. When I first load an mdi child, it's caption consists of "File: no file loaded" and this...
4
by: ToxSox | last post by:
Hello. This is my first post here and i have a big problem with my script! One page (child.htm), was delivered not by me and i can't change it. This page calls a methode in a object of my page....
4
by: Buddha | last post by:
Hello, I posted this on two forums, without too much help .. and I am kinda stuck in this. I need to refresh the parent page from the second child window which is opened by the first child and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.