By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Inserting image nodes in Safari

P: n/a
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).
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lutz Iler wrote:
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.

--
Rob
Jul 23 '05 #2

P: n/a
Hi RobG,

RobG schrieb:
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.-
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.