473,756 Members | 9,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.locat ion.href = 'http://www.google.co.u k';

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.onloa d = windowLoaded;
newWindow.docum ent.onload = windowLoaded;
newWindow.addEv entListener('on load', windowLoaded, true);
newWindow.docum ent.addEventLis tener('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 19309

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.locat ion.href = 'http://www.google.co.u k';

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.onloa d = windowLoaded;
newWindow.docum ent.onload = windowLoaded;
newWindow.addEv entListener('on load', windowLoaded, true);
newWindow.docum ent.addEventLis tener('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.locat ion.href = 'http://www.google.co.u k';

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.onloa d = windowLoaded;
newWindow.docum ent.onload = windowLoaded;
newWindow.addEv entListener('on load', windowLoaded, true);
newWindow.docum ent.addEventLis tener('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********@gma il.comwrote in news:1167542962 .890494.88000
@i12g2000cwa.go oglegroups.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********@gma il.comwrote in news:1167542962 .890494.88000
@i12g2000cwa.go oglegroups.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********@gma il.comwrote in news:1167542962 .890494.88000
@i12g2000cwa.go oglegroups.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...@gm ail.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...@gma il.comwrote in news:1167542962 .890494.88000
@i12g2000cwa.go oglegroups.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
1493
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 (i.e. successfully executing window.open() in Mozilla 1.5; however, I've observed it to work a few times in IE 6.0 and Opera 5.something. It does not seem to be a timing thing -- if I re-call the function somewhat later using setTimeout it still...
4
4917
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'); window.resizeTo(810,750); top.outerWidth=810;
6
4578
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 to tell if the window.onload event has already fired. I cannot edit the onload event handler itself, and my function can only exist in an external js file, sourced from the document's head section. Any ideas?
5
2793
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 save the contents of the form, and then I put an onload event to do a window.close. this works fine for hundreds of people on different browsers. However, for one user the window does not close.
6
9567
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 = 'http://www.blah blah blah.com'; But when I try to set an event handler this way, as shown below, it fails. parent.ToolMenuFrame.window.document.body.onload = "alert('On Load Trigger Fired!!');"; parent.ToolMenuFrame.document.body.onload = "alert('On Load...
1
2143
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
4062
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 user looking at window A clicks the "open window B" link, I want
1
3806
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 problem is that the ITV gets executed for the first time on document's onload method. When the page has few thumb images there are no problems. But when you have big galeries, the behavior of anchors/links isn't the desired until the ITV runs. So I...
0
9679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7078
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3651
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.