473,402 Members | 2,050 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,402 software developers and data experts.

Opening a new window and attaching an onload event listener.

Daz
Hello everyone,

I would like to open a child window from the parent, and add an onload
event listener to the child window which will tell the parent when the
document has loaded. As far as I know, this shouldn't be an issue, but
I just can't get it to work. The script only needs to work with
Firefox/Mozilla, so XP code isn't an issue.

I have tried to open a window like so.

var newWindow = open('','','');

This works as expected.
Next I redirect the child window:

newWindow.location.href = 'http://www.google.co.uk';

Again, this works no problem.
before the child window is redirected, I have tried several methods of
adding an onload event listener to the window, from the script inside
the parent window, but nothing seems to work. I have tried:

newWindow.onload = windowLoaded;
newWindow.document.onload = windowLoaded;
newWindow.addEventListener('onload', windowLoaded, true);
newWindow.document.addEventListener('onload', windowLoaded, true);

None of which seem to work. Please could someone explain where I have
screwed up?

Many thanks.

Daz.

Dec 30 '06 #1
6 19206

Daz wrote:
Hello everyone,

I would like to open a child window from the parent, and add an onload
event listener to the child window which will tell the parent when the
document has loaded. As far as I know, this shouldn't be an issue, but
I just can't get it to work. The script only needs to work with
Firefox/Mozilla, so XP code isn't an issue.

I have tried to open a window like so.

var newWindow = open('','','');

This works as expected.
Next I redirect the child window:

newWindow.location.href = 'http://www.google.co.uk';

Again, this works no problem.
before the child window is redirected, I have tried several methods of
adding an onload event listener to the window, from the script inside
the parent window, but nothing seems to work. I have tried:

newWindow.onload = windowLoaded;
newWindow.document.onload = windowLoaded;
newWindow.addEventListener('onload', windowLoaded, true);
newWindow.document.addEventListener('onload', windowLoaded, true);

None of which seem to work. Please could someone explain where I have
screwed up?
When you open your popup, it contains an empty document. You attach an
onload handler to the empty document, then re-direct the URL so that
document is destroyed and a new one is loaded.

You have to put the onload handler in the new document, you can't
attach it from the calling page unless you actually write the document
from the calling page (say using document.write).
--
Fred.

Dec 30 '06 #2
Daz

Fred wrote:
Daz wrote:
Hello everyone,

I would like to open a child window from the parent, and add an onload
event listener to the child window which will tell the parent when the
document has loaded. As far as I know, this shouldn't be an issue, but
I just can't get it to work. The script only needs to work with
Firefox/Mozilla, so XP code isn't an issue.

I have tried to open a window like so.

var newWindow = open('','','');

This works as expected.
Next I redirect the child window:

newWindow.location.href = 'http://www.google.co.uk';

Again, this works no problem.
before the child window is redirected, I have tried several methods of
adding an onload event listener to the window, from the script inside
the parent window, but nothing seems to work. I have tried:

newWindow.onload = windowLoaded;
newWindow.document.onload = windowLoaded;
newWindow.addEventListener('onload', windowLoaded, true);
newWindow.document.addEventListener('onload', windowLoaded, true);

None of which seem to work. Please could someone explain where I have
screwed up?

When you open your popup, it contains an empty document. You attach an
onload handler to the empty document, then re-direct the URL so that
document is destroyed and a new one is loaded.

You have to put the onload handler in the new document, you can't
attach it from the calling page unless you actually write the document
from the calling page (say using document.write).
--
Fred.
So basically, I need to initiate the page load, and then attach the
event listener? I'm not sure if that will work. I could right, say a
carriage return to the child window, but as soon as I change the
location of the page, I will no doubt lose the event handler.

What I don't understand, is why I can't attach it to the window, as
opposed to the document.

What I am trying to achieve, is an application which can run from the
parent window, and use the child window to navigate to various pages on
the site, and get information from each page (such as links, and user
specific information), so it will effectively work as a macro, saving
the user time waiting for pages to load and clicking on more links. I
am not sure the best way to go about doing this, and the best way I
could think of (above), clearly isn't going to work...

Thank you for your comments Fred. :)

Dec 31 '06 #3
"Daz" <cu********@gmail.comwrote in news:1167542962.890494.88000
@i12g2000cwa.googlegroups.com:
...attach the event listener...
What I don't understand, is why I can't attach it to the window, as
opposed to the document.
Oh, you can attach it to the window, all right, but as soon as you direct
the window to a new URL, what happens? The window discards your attachment
and loads a whole new page.
Dec 31 '06 #4
Daz

Jim Land (NO SPAM) wrote:
"Daz" <cu********@gmail.comwrote in news:1167542962.890494.88000
@i12g2000cwa.googlegroups.com:
...attach the event listener...
What I don't understand, is why I can't attach it to the window, as
opposed to the document.

Oh, you can attach it to the window, all right, but as soon as you direct
the window to a new URL, what happens? The window discards your attachment
and loads a whole new page.
Oh I see. I keep getting confused between document, and window. I
thought it was the _document_ being redirected, not the window. Hehe.

Thanks for clearing that up for me Jim. :)

Dec 31 '06 #5
Hi.
I've been struggling with the very same issue for the past few days. I
want to be able to load a new document from a parent window and read
some parameters from the newly opened document. I too, tried attaching
an onload event to the new document, but got undefined values when
trying to read values from the new document. I couldn't find-out why,
until this thread gave me the answer. So, thanks. But, still, I didn't
achieve my goal yet, is there a way it can be done?
Thanks,
- Yuval

Daz כתב:
Jim Land (NO SPAM) wrote:
"Daz" <cu********@gmail.comwrote in news:1167542962.890494.88000
@i12g2000cwa.googlegroups.com:
...attach the event listener...
What I don't understand, is why I can't attach it to the window, as
opposed to the document.
>
Oh, you can attach it to the window, all right, but as soon as you direct
the window to a new URL, what happens? The window discards your attachment
and loads a whole new page.

Oh I see. I keep getting confused between document, and window. I
thought it was the _document_ being redirected, not the window. Hehe.

Thanks for clearing that up for me Jim. :)
Feb 9 '07 #6
Daz
On Feb 9, 5:16 am, yuval.inv...@gmail.com wrote:
Hi.
I've been struggling with the very same issue for the past few days. I
want to be able to load a new document from a parent window and read
some parameters from the newly opened document. I too, tried attaching
an onload event to the new document, but got undefined values when
trying to read values from the new document. I couldn't find-out why,
until this thread gave me the answer. So, thanks. But, still, I didn't
achieve my goal yet, is there a way it can be done?
Thanks,
- Yuval

Daz כתב:
Jim Land (NO SPAM) wrote:
"Daz" <cutenfu...@gmail.comwrote in news:1167542962.890494.88000
@i12g2000cwa.googlegroups.com:
...attach the event listener...
What I don't understand, is why I can't attach it to the window, as
opposed to the document.
Oh, you can attach it to the window, all right, but as soon as you direct
the window to a new URL, what happens? The window discards your attachment
and loads a whole new page.
Oh I see. I keep getting confused between document, and window. I
thought it was the _document_ being redirected, not the window. Hehe.
Thanks for clearing that up for me Jim. :)
I think the only solution would be to have a small function in the
child window that executes a function in the parent window onload. You
also need to ensure that the child window is served from the same
domain as the parent window.

Feb 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Starry Gordon | last post by:
I've been running some small test programs which seem to indicate something noticed in a larger script, that a function called from onLoad() in the <body> tag will not succeed in creating a window...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
5
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to...
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
1
by: webgour | last post by:
Hello, I would like to create an onload event within my object. The following works fine : function TEST() { this.image= new Image(); } TEST.prototype.Initialize = function()
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
1
Cristian Pinheiro
by: Cristian Pinheiro | last post by:
Hello guys, I was playing with Image Thumbnail Viewer (ITV) and found one problem, see http://www.dynamicdrive.com/dynamicindex4/thumbnail.htm for more details and how it works. Now the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.