473,320 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Inserting image nodes in Safari

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
2 2042
Lutz Ißler 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
2
by: Henri Sivonen | last post by:
I try to associate DOM nodes with other objects. Assigning custom properties to DOM nodes works in Firefox and Safari. It also works with HTML nodes in IE6. However, it appears not to work with XML...
5
by: Bob | last post by:
Hi, I have a treeview which contains nodes of a class (classA) derived from treenode. These classA nodes may contain nodes of a class (ClassB) derived from classA. The form load populates a...
2
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading...
7
by: petermichaux | last post by:
Hi, I have tried the following based on suggestions of the best way to insert JavaScript into a page. This is instead of using eval(). Unfortunately IE says "unexpected call to property or...
7
by: fredo | last post by:
I've studied Eric Meyer's pure css popups, version two: http://meyerweb.com/eric/css/edge/popups/demo2.html which pops up an image when I roll over a text link. Now I want to pop up a large...
2
by: cesarcesar | last post by:
Hi, XML novice here with another question. I need to add a XML node like, <child01> <child02> <text></text> <image>image 1</image> <image>image 2</image>
7
by: David Stone | last post by:
Run into something recently that has left me a little puzzled. According to the examples in section 13.6.1 of html 4.01... <http://www.w3.org/TR/html401/struct/objects.html#h-13.6.1.1> I...
2
by: SMH | last post by:
I am in the process of converting all HTML documents, including many dynamic/interactive documents, to XHTML documents (because I want to incorporate SVG and MathML, among other things). I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.