Connecting Tech Pros Worldwide Forums | Help | Site Map

Check for failure after appendChild inserts a document?

-Lost
Guest
 
Posts: n/a
#1: Jan 27 '07
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



VK
Guest
 
Posts: n/a
#2: Jan 27 '07

re: Check for failure after appendChild inserts a document?


On Jan 27, 10:27 pm, "-Lost" <spam_ninjaREMOV...@REMOVEMEcomcast.net>
wrote:
Quote:
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/>
Quote:
if (appendChild('css_doc.css'))
This obviously would lead to run-time error. I presume you meant to
say appendChild(linkObject)

-Lost
Guest
 
Posts: n/a
#3: Jan 28 '07

re: Check for failure after appendChild inserts a document?


"VK" <schools_ring@yahoo.comwrote in message
news:1169937546.332567.42950@q2g2000cwa.googlegrou ps.com...
Quote:
On Jan 27, 10:27 pm, "-Lost" <spam_ninjaREMOV...@REMOVEMEcomcast.net>
wrote:
Quote:
>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.
Quote:
Quote:
>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


Closed Thread