Reusable Image Cache in JS => NS_ERROR_DOM_HIERARCHY_REQUEST_ERR

J

Josselin

(Mac 10.4.6 , Firefox/1.5.0.3 Mozilla/5.0 (Macintosh; U; PPC Mac OS X
Mach-O; fr; rv:1.8.0.3) Gecko/20060426 )

I am trying to setup a Reusable Image Cache in JS ( as per
http://www.devx.com/webdev/Article/20947 )

In order to o survey the events from image loading in a group
container, It seems necessary to perform the following function,
ImagePair(file) .
Unfortunatly Firefox javascript checking mentions an error with this
function :
=> document.appendChild(this.image);

does anyone have a hint about it ?

------ JS function --------------
function ImagePair( _file ) {
// The ImagePair object's purpose is to keep track of the image and
the file that identifies it;
// we do this because the image's src attribute will read back as
uuencoded if interrogated, // meaning that, to see if a particular
image exists in the cache, we need to uuencode
// again. It seems easier just to store the path in unencoded form,
along with the image //associated with it.

this.file = _file;
this.image = new Image();

// Add the image to the document; if you don't, readystatechange
// events won't know where they originated, meaning that
event.srcElement will be null
document.appendChild(this.image);
}

----------- error message
Erreur : uncaught exception: [Exception... "Node cannot be inserted at
the specified point in the hierarchy" code: "3" nsresult: "0x80530003
(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" location:
"http://www.ecolabs.loc/scripts_js/load-image.js Line: 82"]
 
R

Richard Cornford

Josselin wrote:
=> document.appendChild(this.image);

does anyone have a hint about it ?
Erreur : uncaught exception: [Exception... "Node cannot
be inserted at the specified point in the hierarchy"
<snip>

The hierarchy in question is the tree-like hierarchy of the DOM. The
document is at the absolute root of the DOM and the (x)HTML elements in
the mark-up are descendants of the document, with the outermost
containing element (usually http) as a direct child of the document and
all other elements decentness of the HTML element.

There are restrictions on where various elements may appear in this
tree-like structure and IMG elements must be, at minimum, descendants of
the BODY element. You are trying to insert an IMG at the same level as
the HTML element, which does not make sense in terms of an (x)HTML
document structure, and some browsers will generate errors in response.

Richard.
 
R

Richard Cornford

Richard Cornford wrote:
... , with the outermost containing element
(usually http) as a direct child of the document ^^^^
and all other elements decentness of the HTML element.
<snip>

That should have been "... outermost containing element (usually html)
...."

i.e. The html element is the outermost element in an (x)HTML document.
All other elements are its descendants, with its direct children being
the head and body elements. (Processing instructions, such as DOCTYPE
and comments are strictly Nodes in this context. DOCTYPE may be a
(preceding) sibling of the html element, if it is represented in the
DOM. Text nodes, representing non-significant white space, may also
appear as direct children of the document, and so siblings of the html
element).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top