HighDots Forums  

Re: Inserting image nodes in Safari

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Inserting image nodes in Safari in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RobG
 
Posts: n/a

Default Re: Inserting image nodes in Safari - 05-05-2005 , 07:02 PM






Lutz Ißler wrote:
Quote:
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.

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.