Inserting image nodes in Safari

L

Lutz Ißler

Hi all!

I dymically replace the child nodes of a DIV element by image nodes. In
IE and Firefox this works properly. In Safari it works properly, too -
but only if the site is called locally, eg. with file://. Uploading to a
server and viewing the site in Safari with http:// results in an error.

The problematic code is the following:

var node = document.createElement("img");
node.setAttribute("src", filename);
node.setAttribute("style", "position:absolute;left:100px;"); // error
document.getElementById(name+"Images").appendChild(node);

When executing this script on Safari in online mode (again: with a
_local_ file, it works fine!), Safari reports the following error,
occuring in the marked line:

"[592] :TypeError - No default value"

Obviously, node.style seems not available at this point. I think
Safari's still loading the image, and while loading it blocks all
accesses to node.

Is this assumption correct?

That would mean that in Safari, I cannot do _anything_ with the image
node until the image is loaded. These are not really bright prospects.

Regards,

-.Lutz.-

PS: I tried to enclose the image nodes in DIV elements and to apply
style properties to the DIVs. That lead to a DOMException 8 ("node does
not exist") when calling appendChild(node).
 
R

RobG

Lutz said:
Hi all!

I dymically replace the child nodes of a DIV element by image nodes. In
IE and Firefox this works properly. In Safari it works properly, too -
but only if the site is called locally, eg. with file://. Uploading to a
server and viewing the site in Safari with http:// results in an error.

The problematic code is the following:

var node = document.createElement("img");
node.setAttribute("src", filename);
node.setAttribute("style", "position:absolute;left:100px;"); // error
document.getElementById(name+"Images").appendChild(node);

When executing this script on Safari in online mode (again: with a
_local_ file, it works fine!), Safari reports the following error,
occuring in the marked line:

"[592] :TypeError - No default value"

Obviously, node.style seems not available at this point. I think
Safari's still loading the image, and while loading it blocks all
accesses to node.

Is this assumption correct?

Sorry, I can't test this right now but... if your assumption is
correct, modifying the style before the src attribute should work.
That would mean that in Safari, I cannot do _anything_ with the image
node until the image is loaded. These are not really bright prospects.

Regards,

-.Lutz.-

PS: I tried to enclose the image nodes in DIV elements and to apply
style properties to the DIVs. That lead to a DOMException 8 ("node does
not exist") when calling appendChild(node).

var node = document.createElement('img');
node.alt = 'Picture of something';
node.style.position = 'absolute';
node.style.left = '100px';
document.getElementById(name + 'Images').appendChild(node);
node.src = filename;

Generated elements should comply with HTML 4 (or whatever DOCTYPE
you're using), so you need an 'alt' attribute too.
 
L

Lutz Ißler

Hi RobG,
Sorry, I can't test this right now but... if your assumption is
correct, modifying the style before the src attribute should work.

No it doesn't.
Generated elements should comply with HTML 4 (or whatever DOCTYPE
you're using), so you need an 'alt' attribute too.

Thanks for the tip.

In the meantime, I found the problem cause: the Content-Type header was
not matching the DOCTYPE declaration. IE and Firefox ignored that but
Safari didn't. Now, with matching text/html and HTML 4.01 DOCTYPE,
everything works as expected even with Safari online.

Thank you for the help,

-.Lutz.-
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top