473,698 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating DOM elements in IE before page complete

dd
Has anyone found a way around the problem IE has if you create elements
(script or div, doesn't seem to matter) BEFORE the document.readyS tate
is "complete" ?

I know you can sometimes get away with only waiting for "interactiv e"
state, but I've found that on some pages, that can result in a weird
error with a dialog box along the lines of "Internet operation aborted
error" (or something like that, I haven't seen it for a long time since
I implemented the having to wait for "complete" so I can't be sure of
the wording).

I'd really like to be able to dynamically create script and div
elements without waiting for at least interactive. In a related
question, does anyone know why some pages don't get past interactive
state despite the status bar showing "done" ? You can see how that's
naturally screwing me up if I'm waiting for complete and/or an onload
event.

Jan 8 '07 #1
8 2496

dd wrote:
Has anyone found a way around the problem IE has if you create elements
(script or div, doesn't seem to matter) BEFORE the document.readyS tate
is "complete" ?
AFAIK, document.readyS tate is a Microsoft invention introduced in
support of FrontPage extensions; it has been adopted by some other
browsers (but not Firefox AFAIK). The readyState property is also part
of the (Microsoft inspired) XMLHttpRequest Object specification[1], but
as a property of the request object, not the document.

If you want to know when you can safely start modifying the document,
your best bet is to wait for the load event (window.onload =
someFunction).

If you want to do DOM changes before then, then you need to wait for
elements to exist (e.g. place the script immediately after the closing
tag of the element you want to modify). If you are doing it from the
head and before the load event has occurred, expect problems.
>
I know you can sometimes get away with only waiting for "interactiv e"
state, but I've found that on some pages, that can result in a weird
error with a dialog box along the lines of "Internet operation aborted
error" (or something like that, I haven't seen it for a long time since
I implemented the having to wait for "complete" so I can't be sure of
the wording).

I'd really like to be able to dynamically create script and div
elements without waiting for at least interactive. In a related
question, does anyone know why some pages don't get past interactive
state despite the status bar showing "done" ? You can see how that's
naturally screwing me up if I'm waiting for complete and/or an onload
event.
That sounds very IE-specific. If that is your intention, you should
try an IE forum with a link to a test page.
1. 3rd working draft: <URL: http://www.w3.org/TR/XMLHttpRequest/ >

--
Rob

Jan 8 '07 #2
dd
RobG wrote:
If you want to know when you can safely start modifying the document,
your best bet is to wait for the load event (window.onload = someFunction).
If you want to do DOM changes before then, then you need to wait for
elements to exist (e.g. place the script immediately after the closing
tag of the element you want to modify). If you are doing it from the
head and before the load event has occurred, expect problems.
Yeah, I've been hoping to avoid that. My code is deployed within the
body
so the </bodytag definitely won't have been executed yet. I think
when
that happens the state of the document changes to "interactiv e" while
it's
waiting for images to finish loading. Somehow even this is too early
sometimes though.

RobG wrote:
That sounds very IE-specific. If that is your intention, you should
try an IE forum with a link to a test page.
Yeah I've tried IE forums in the past without success. I wasn't really
expecting
a successful answer. Everything I've seen in the past indicate I need
to wait
for onload. It was worth a try :)

Jan 8 '07 #3
VK

dd wrote:
Has anyone found a way around the problem IE has if you create elements
(script or div, doesn't seem to matter) BEFORE the document.readyS tate
is "complete" ?
Before the page is loaded, the document DOM tree is not completed yet.
Respectively you cannot manipulate something that doesn't exist yet:
same way as you cannot set up furniture in a flat before the floor is
build up. There is no difference in this aspect between browsers.

On the loading stage you have text input stream from the server being
sent to (X)HTML parser, this is all. What you can do on this stage is
to temporarily switch the input stream from the server to your script,
output the needed text stream segment to the parser and switch back to
the server-generated stream. In javascript you do it by using
document.write( ) method.

.... HTML page source ...
<script type="text/javascript">
document.write( yourSourceToPar se);
</script>
.... the rest of HTML page source

Jan 8 '07 #4
dd
VK wrote:
Before the page is loaded, the document DOM tree is not completed yet.
That I agree with.
Respectively you cannot manipulate something that doesn't exist yet:
Not quite what you first said. I agree it's not complete, but to say
it doesn't exist is going a bit far. It does exist, it's just not
complete.

VK wrote:
same way as you cannot set up furniture in a flat before the floor is
build up.
Taking that analogy too far I think. I'd say the floor in the flat is
busy
being built by a few guys going from one side of the room to the other
and I'm just asking them if I can place some furniture "behind them"
onto the piece of floor they've already finished, even if the glue
isn't
dry yet :)

VK wrote:
There is no difference in this aspect between browsers.
There's a HUGE difference. All other browsers allow inserting/adding
of items to the DOM before the page has finished parsing. Only IE
has a hissy fit if you mess with the incomplete floor.

Jan 8 '07 #5
VK

dd wrote:
VK wrote:
Before the page is loaded, the document DOM tree is not completed yet.

That I agree with.
Respectively you cannot manipulate something that doesn't exist yet:

Not quite what you first said. I agree it's not complete, but to say
it doesn't exist is going a bit far. It does exist, it's just not
complete.
It doesn't exist as a finalized scriptable unit where you could apply
DOM methods.
VK wrote:
same way as you cannot set up furniture in a flat before the floor is
build up.

Taking that analogy too far I think. I'd say the floor in the flat is
busy
being built by a few guys going from one side of the room to the other
and I'm just asking them if I can place some furniture "behind them"
onto the piece of floor they've already finished, even if the glue
isn't
dry yet :)
And they kick you out plus giving a nock to the behind: until the level
is finished: for personnel only.
:-)
VK wrote:
There is no difference in this aspect between browsers.

There's a HUGE difference.
Noop. You are cheated by the parser optimisation and look-ahead
mechanics. Try this for instance:

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Header</h1>
<script>
try {
var p = document.create Element('p');
p.innerHTML = '<em>Extra paragraph</em>';
document.body.a ppendChild(p);
}
catch(e) {
document.write( '<p style="color:re d">' + e.message + '</p>');
}
</script>
<p>Paragraph</p>
</body>
</html>

Both FF and IE will show "Extra paragraph". Did you really managed to
script DOM Tree before it came into existence? No at all. The parser
just gave a micro-delay in script execution to see if it can parse and
finalize DOM during this delay. So your inline script in fact was
implicetly converted into window.onload=a ddParagraph.

Can you relay on this behavior? I would insistently suggest never do
it. Next time you page will be more complicated or connection slower
and oops: "document.b ody is null or not an object".

Once again, for any robust solution the mantra is:

before page load event - document.write only
after page load event - DOM methods only
Ommm...
....
before page load event - document.write only
after page load event - DOM methods only
Ommm...
....

Repeat 10 times before go to bed and the life becomes much more easy
and your customers will stay happy, and money will stay in your house.

:-)

Jan 8 '07 #6
VK wrote:
<snip>
VK wrote:
There is no difference in this aspect between browsers.
There's a HUGE difference.

Noop. You are cheated by the parser optimisation and look-ahead
mechanics. Try this for instance:

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Header</h1>
<script>
try {
var p = document.create Element('p');
p.innerHTML = '<em>Extra paragraph</em>';
document.body.a ppendChild(p);
}
catch(e) {
document.write( '<p style="color:re d">' + e.message + '</p>');
}
</script>
<p>Paragraph</p>
</body>
</html>

Both FF and IE will show "Extra paragraph".
But they both (and Opera for that matter) show "Extra paragraph" above
"Paragraph" and below "Header", suggesting that it was inserted into
the DOM before the pragraph element defined in the HTML source.
Did you really managed to script DOM Tree before it came into
existence? No at all.
No, but it was scripted before it was finished, and certainly before
all the HTML had been parsed into DOM nodes.
The parser just gave a micro-delay in script execution
You just love to make this rubbish up off the top of your head.
to see if it can parse and finalize DOM during this delay.
You have no evidence for this, and your code contradicts it as the -
document.body.a ppendChild(p); - line appears to have appended the new
paragraph to the BODY element at precisely the point where the line of
code was called. Thus the new paragraph is the nextSibling of the
SCRIPT element and the previousSibling of the P element defined in the
HTML.
So your inline script in fact was
implicetly converted into window.onload=a ddParagraph.
<snip>

If that were true then the new paragraph would have been appended at
the end of the BODY element, as its last child, and so _after_ the
paragraph that was defined in the HTML. In reality it was clearly
inserted before that paragraph, and so your assertion is, as usual,
false.

I realise that analysis has never been one of your skills but even you
should have been able to look at the order of output on the page and
seen that what you were proposing made no sense what so ever.

Richard.

Jan 8 '07 #7
RobG said the following on 1/8/2007 1:21 AM:

<snip>
1. 3rd working draft: <URL: http://www.w3.org/TR/XMLHttpRequest/ >
<quote>
A future version or extension of this specification will define a way of
doing cross-site requests.
</quote>

"cross-site"? I have never liked the way those documents are worded. Is
that the same as cross-domain or is it referring to sub-domains?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 8 '07 #8
dd
VK wrote:
>
Both FF and IE will show "Extra paragraph". Did you really managed to
script DOM Tree before it came into existence? No at all. The parser
just gave a micro-delay in script execution to see if it can parse and
finalize DOM during this delay. So your inline script in fact was
implicetly converted into window.onload=a ddParagraph.
No, it did exist. Both show Extra paragraph before paragraph
implying it worked exactly the same as a document.write. I've
always known that would be the case.

My problem is that if you do that on IE, then somehow the
DOM becomes instable and can lead to later errors of the
likes of "Internet operation aborted". It was happening when
I was loading content into iframes dynamically. When I went
back to the earlier apparently unrelated DOM additions and
made them wait for "complete" then my dynamic loading into
iframes no longer got that error.

Jan 8 '07 #9

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

Similar topics

2
2344
by: Alan Morris | last post by:
I would like to write a generalised page which creates an email containg the (calling) HTML form complete with the user populated data. In this way the appearance of the email will be just like the form elements of the form that called the generalised page together with the completed fields. I can see that I can caputure the (blank) calling page itself in the email by using the CreateMHTMLBody method of CDO. I can also see how I
6
2945
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the script created them. It used things like parentnode, insertBefore, appendChildNode,... Any ideas/direction is appreciated.
3
2343
by: Vince Mele | last post by:
We are having a small problem with a couple of reports we developed for a client website. On two of the reports, sometimes (most of the time) we receive a warning message before the output of the report is presented in the browser. The warning message says "This page contains both secure and non-secure items. Do you want to display the non-secure items Yes, No, Cancel)". The site was developed using ASP.NET, VB.NET, and Crystal Reports...
9
3918
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object', 'Scripting', 'Scripting.FileSystemObject', and a few others However, when I try to create the fso object I keep receiving an error. 'ActiveX component can't create object: 'Scripting.FileSystemObject'
2
1943
by: stealth_spoof | last post by:
Hi People wondering if anyone can help me with a problem I'm having I'm trying to create an array with an unspecified length, the length is based on the result i get from another task in the code that I have what I have so far is a page that has a text box for user input, which will take whatever the user enters, will count all the characters in the inputted text which also then uses the "split" command, to split the users text...
1
2484
by: Agent Michael Scarn | last post by:
Hello All, After I submit a form it goes to a post page where I have a javascript that creates one variable that has all of the element names from the form listed out like so: var1=var1&var2=var2&var3=var3 and so on...
5
2812
by: Richard Gromstein | last post by:
Hello, I have an exercise that I need to finish very soon and I really need help understanding what to do and how exactly to do it. I am working on reading the chapter right now and working on it myself, but I have a feeling I won't get far. Please help me complete the exercise. I am posting what needs to be done and will be updating with pieces of code that I come up with. Thank you all for your attention. ...
37
3663
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry over" when there are <br /tags involved...??? I've tried using <p style="font-weight: bold;"></p>, I've tried <blockquote></blockquote>...I just can't figure how I'm supposed to get the <b></btags to work for all the lines! Surely there must be...
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8901
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
8871
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...
0
7739
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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
5862
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
4371
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
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.