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

Check for failure after appendChild inserts a document?

Is it possible to check if a file was not included properly?

For example, I am using appendChild to insert a CSS document into the HEAD of my HTML
document. I tested it with a non-existent CSS file, but no errors are thrown. For
example:

if (appendChild('css_doc.css'))
{
alert('OK');
}
else
{
alert('Not OK');
}

css_doc.css does not exist, but the alert fires 'OK' either way. (I also tried it with a
try/catch, but it also does not throw an error.)

Thanks.

-Lost
Jan 27 '07 #1
2 1586
VK
On Jan 27, 10:27 pm, "-Lost" <spam_ninjaREMOV...@REMOVEMEcomcast.net>
wrote:
Is it possible to check if a file was not included properly?
appendChild doesn't include any files - it simply adds new element to
the document DOM Tree. At the moment of adding new <linkor <script>
element it doesn't know neither it cares if src string attribute value
points to some existing document. It even doesn't care if src
attribute is a valid URL. It just an opaque string for it to use as
attribute value. So no, this kind of check is not possible.
On IE <linkelement has onerror handler you could use but this
handler is not supported by others. The only cross-browser option is
to choose some "key rule" in the stylesheet and periodically check if
it is set during some period of time. jsNet is based on this technique
<http://jsnet.sourceforge.net/>
if (appendChild('css_doc.css'))
This obviously would lead to run-time error. I presume you meant to
say appendChild(linkObject)

Jan 27 '07 #2
"VK" <sc**********@yahoo.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
On Jan 27, 10:27 pm, "-Lost" <spam_ninjaREMOV...@REMOVEMEcomcast.net>
wrote:
>Is it possible to check if a file was not included properly?

appendChild doesn't include any files - it simply adds new element to
the document DOM Tree. At the moment of adding new <linkor <script>
element it doesn't know neither it cares if src string attribute value
points to some existing document. It even doesn't care if src
attribute is a valid URL. It just an opaque string for it to use as
attribute value. So no, this kind of check is not possible.
On IE <linkelement has onerror handler you could use but this
handler is not supported by others. The only cross-browser option is
to choose some "key rule" in the stylesheet and periodically check if
it is set during some period of time. jsNet is based on this technique
<http://jsnet.sourceforge.net/>
Well that sucks. JSONet looks like it will work great though! Thanks for the link.
>if (appendChild('css_doc.css'))
This obviously would lead to run-time error. I presume you meant to
say appendChild(linkObject)
Right, sorry about that. I thought about it after I posted but figured everyone would get
the gist of it.

Thanks again.

-Lost
Jan 28 '07 #3

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

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
1
by: Eli | last post by:
Hi, I've created a dynamic IFRAME and inserted it in the document. Then I changed the src property to some URL (not the same domain as the main document). I want to check when the IFRAME is...
3
by: Robi | last post by:
I have the following code: ############## var nHead=(document.getElementsByTagName)?document.getElementsByTagName("head").item(0):document.head; var nStyle=document.createElement("style"); //...
2
by: Howard Jess | last post by:
CLJ -- I've searched the newsgroup and FAQ for info on insertRow(), but didn't see this reported. It seems that Internet Explorer doesn't respond correctly to either insertRow() or...
3
by: ezmiller | last post by:
So I have some code that gets the body element of another frame and then tries to dynamically write a table. The code fails when, after creating the table, I try to append it to the document. I...
3
by: stephen.cunliffe | last post by:
I hope the subject doesn't get escaped, but I'll try to clarify here... I have: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> in my head (and yes, I need to keep it...
2
by: Christina | last post by:
I have 2 list boxes - one to fill the second one based on the selection, or move all items. You can remove the selection (or all items) from the second one to place it back in the first one. I...
2
by: vsanjit | last post by:
Hi all, I've been trying to create a table dynamically upon the generation of en event using the appendChild method in Javascript. This seems to work fine in Firefox, but not in IE7. There's also...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.