Forum Moderators: open
document.getElementById('table'+row+'td'+b).innerHTML = document.images[image]['title']; alert('images 0 = ' + document.images[0]['title']); for (var n=0; n<document.images.length; n++) {
document.writeln(n + ' - ' + document.images[n]['src']);
}
What can I do to get round this?
document.images, you can use the NodeList as returned by
document.getElementByTagName('img') instead. However, both should return comparable results and if one is broken I suspect the other is too. I would persevere with document.imagesto see what the underlying cause is.
Got it - using Opera's Dragonfly I can view the HTML generated by the script. There's a hidden SPAN with an IMG in it of size 0, positioned -999ems off the screen! Even so, this should appear in all browsers, surely? And certainly be part of the document.images array.
I can try adding an image with script...
for (var n=0; n<document.images.length; n++) {
if (document.images[n]['src'].indexOf('geo.yahoo.com') > -1) {
continue;
}
document.writeln(n + ' - ' + document.images[n]['src']);
} if ((n == 0) && document.images[n]['src'].indexOf('geo.yahoo.com') > -1) {
Regarding your first loop, I only ever get one line output from that. Document write stops after the first echo.
One last thing - what else can document.images give you? Can it reveal the date the image was uploaded? That would be very useful.
document.images[n]['fileCreatedDate']in IE and it will return a string of the form '07/19/2011' (NB: US Formatted it seems). However, Chrome and Opera return none of these (I've not checked Firefox).
var output = '';
var img = document.images[0];
for (var imgProp in img) {
output += '<li>' + imgProp + ' (' + typeof img[imgProp] + ') = ';
try {
output += img[imgProp];
} catch(e) {
output += '-ERROR-';
}
output += '</li>';
}
document.write('<ol>' + output + '</ol>');
I tested the document write loop in more browsers than IE. They all showed one line only.
Does "writeln" mean write then make a new line?
OK, done some more tests. I get just ONE line in ALL browsers. Maybe because of the way the script is inside a function called onload?
Not sure where you get the low number for Chrome from.
OK, done some more tests. I get just ONE line in ALL browsers. Maybe because of the way the script is inside a function called onload?
Because onload event handlers are invoked after document parsing is complete, they must not call document.write(). Instead of appending to the current document, any such call would instead begin a new document and overwrite the current document before the user even had a chance to view it.
As a general rule of thumb, a document should never call write() on itself from within an event handler.