473,406 Members | 2,707 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,406 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 1608

"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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.