473,396 Members | 1,921 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,396 software developers and data experts.

Firefox not loading dom quickly enough: how to wait?

I am making some popup windows, and then trying to load content into
them. It can be as few as two windows, and as many as 15 or so. I'm
running into a problem where firefox cannot find the
popupwindow.document.body after it loads. If i wait until the popups
are all popped, and *then* try to write into them, the script can find
more windows...but still can't get them all to find the document body
element. It gives me the error "winbody has no properties" when i do
something like this:

<code>
popupwin = window.open( '', 'window_name', '' );
winbody = popupwin.document.body;
winbody.appendChild(popupwin.document.createTextNo de('sometext'));
</code>

So. If that made sense, what i would like is anyone who has an idea
for how i can make the script wait until the browser understands the
DOM before executing more scripts, because i need the win.document.body
to *have* properties, and accept the function appendChild and other
such functions. Any ideas?

Aug 9 '05 #1
5 2527
Donius wrote:
I am making some popup windows, and then trying to load content into
them. It can be as few as two windows, and as many as 15 or so. I'm
running into a problem where firefox cannot find the
popupwindow.document.body after it loads. If i wait until the popups
are all popped, and *then* try to write into them, the script can find
more windows...but still can't get them all to find the document body
element. It gives me the error "winbody has no properties" when i do
something like this:

<code>
popupwin = window.open( '', 'window_name', '' );
winbody = popupwin.document.body;
winbody.appendChild(popupwin.document.createTextNo de('sometext'));
</code>

So. If that made sense, what i would like is anyone who has an idea
for how i can make the script wait until the browser understands the
DOM before executing more scripts, because i need the win.document.body
to *have* properties, and accept the function appendChild and other
such functions. Any ideas?


First of all, Firefox does not have the document.body element, instead refer
to it with window.document.documentElement.

If you still have problems then there are a couple different methods you can
use, but obviously you will have to decide which one works best for your
situation. First of all you could put an onload event into the window you
are opening that fires a method in the opener window. Here's a little code
snippet:

popupwin = window.open(
'<HTML><BODY onload = "window.opener.myContFunction()"></BODY></HTML>',
'window_name', '' );

function myContFunction()
{
winbody = popupwin.document.documentElement;
winbody.appendChild(popupwin.document.createTextNo de('sometext'));
}

If you do that you shouldn't ever have any problems with getting that error
anymore. Another method of achieving things is a little more "squirrely"
and probably not too nice of a coding technique, but it should work. It
uses setInterval to check (every 10 milliseconds in the example below) if
the popupwin.document.body exists yet. Here is an example:

popupwin = window.open(
'<HTML><BODY onload = "window.opener.myContFunction()"></BODY></HTML>',
'window_name', '' );
myInterval = window.setInterval("myContFunction()",10)

function myContFunction()
{
if (popupwin && popupwin.document && popupwin.document.documentElement)
{
cancelInterval(myInterval)
winbody = popupwin.document.documentElement;
winbody.appendChild(popupwin.document.createTextNo de('sometext'));
}
}

Hope you find this helpful!

David
Aug 10 '05 #2
On Tue, 9 Aug 2005 19:58:30 -0700, "David" <dk****@hotmail.com> wrote:
Donius wrote:
So. If that made sense, what i would like is anyone who has an idea
for how i can make the script wait until the browser understands the
DOM before executing more scripts, because i need the win.document.body
to *have* properties, and accept the function appendChild and other
such functions. Any ideas?


First of all, Firefox does not have the document.body element, instead refer
to it with window.document.documentElement.


It doesn't? Are you sure? Why would it choose to ignore standards
for that?

http://www.w3.org/TR/2003/REC-DOM-Le...ml#ID-26809268

Now it's true of course that documentElement would also exist, but
that doesn't mean document.body doesn't.

Jim.
Aug 10 '05 #3
Thanks, both!

(1) Yes, document.body does indeed exist in firefox's JS engine.
(2) The syntax for window.open takes the arguments: (file_name,
window_name, other_arguments_csv_style), as far as i can tell, so i
can't specify content like that
(3) I didn't think that document.write'ing an onload event handler
would work. Not sure why, it just was ruled out in my head as an
option. But when you mentioned it, David, i tried it and viola!
Everything i could have ever wanted. :) Thanks so much! So the basic
was like this:

<code>
popupwin = window.open( '', 'window_name', '' );
windoc = popupwin.document;
windoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<head>\n
</head>\n<body onload="window.opener.myContFunction()">\n</body>");
windoc.close();

function myContFunction(){
winbody = windoc.body;
winbody.appendChild(windoc.createTextNode('sometex t'));
}
</code>

Also the little bit of syntax where you called the function of the
opener...that helped too. I didn't think of scope in that sense...i
just kind of assumed it would all be available to the popup windows as
children of the main. And heck, even if by some craziness they
are...it's cleaner for me to think of the opener as containing all the
useful code. :) Thanks!

-Brendan

Aug 10 '05 #4
Donius wrote:
Thanks, both!

(1) Yes, document.body does indeed exist in firefox's JS engine.
(2) The syntax for window.open takes the arguments: (file_name,
window_name, other_arguments_csv_style), as far as i can tell, so i
can't specify content like that
(3) I didn't think that document.write'ing an onload event handler
would work. Not sure why, it just was ruled out in my head as an
option. But when you mentioned it, David, i tried it and viola!
Everything i could have ever wanted. :) Thanks so much! So the basic
was like this:

<code>
popupwin = window.open( '', 'window_name', '' );
windoc = popupwin.document;
windoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<head>\n
</head>\n<body onload="window.opener.myContFunction()">\n</body>");
windoc.close();

function myContFunction(){
winbody = windoc.body;
winbody.appendChild(windoc.createTextNode('sometex t'));
}
</code>

Also the little bit of syntax where you called the function of the
opener...that helped too. I didn't think of scope in that sense...i
just kind of assumed it would all be available to the popup windows as
children of the main. And heck, even if by some craziness they
are...it's cleaner for me to think of the opener as containing all the
useful code. :) Thanks!

-Brendan


Sorry for the misinformation about the body object not existing, I don't
know how I'd gotten that into my head. I think it's because I had a problem
a while ago that had to do with the body object and I ended up having to use
documentElement instead, and for some reason I'd gotten into my head that
Firefox didn't support the body object like that.

As for using window.open like I specified, I was a little to hasty writing
my code example, instead it should have been as follows:

popupwin = window.open("javascript:document.write(
'<HTML><BODY onload = "window.opener.myContFunction()"></BODY></HTML>')",
'window_name', '' );

And that will work such that when the window loads it runs the code and thus
writes that HTML into the document. However, with that method, you may have
some issues with trying to access the window.opener from the new window due
to cross-domain rules.

Glad you were able to get things working!

David
Aug 10 '05 #5
David wrote:
Sorry for the misinformation about the body object not existing, I don't
know how I'd gotten that into my head. I think it's because I had a problem
a while ago that had to do with the body object and I ended up having to use
documentElement instead, and for some reason I'd gotten into my head that
Firefox didn't support the body object like that.


Well I can confirm that you might stumble into horrible problems if you
use 'normal' DOM properties and methods and combine them with HTML DOM
properties and methods. In my case it had to do with tables.

If you ever see a pure virtual function call error and Internet Explorer
crashes then rewrite your code and take out HTML DOM script.
Aug 12 '05 #6

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

Similar topics

5
by: danny.myint | last post by:
I was under the assumption that javascript loads all the <head></head> elements before processing the <body> tag in Mozilla/Netscape/Firefox. It doesn't seem like it, with my problem. I have...
6
by: Chris Smith | last post by:
This is a bit of a weird problem. Unfortunately, I can't reproduce it in a simple example, so I can only poke it out there and see if anyone has seen something similar. I have a script that...
1
by: shankwheat | last post by:
I use this code to populate a selectbox with a group of records from a database. It executes very quickly with FireFox 2.0 but takes 7-10 secs with IE6 and IE7. Just wondering if anyone had any...
7
by: amishguy | last post by:
Hello, I am having an issue with a site I'm creating right now. I have had this issue before and I would like to figure out what the solution is instead of using workarounds as I have in 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: 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
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
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...
0
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...
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,...

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.