DOM_scripter wrote:
Hi, I want to set a picture on the fly. For this I have a html file
with only an <img> tag - kind of a placholder.
So I do myWindow=window.open("data/myFile.html"). Then I set the src
attribute of the img object to the image I ant to show. I thought I
could do this by myWindow.img.src but this does not work. Even
myWindow.img.src.URL gives me an undefined so I wonder, is DOM access
of an object I get via "window.open" possible at all?
You may want to learn the DOM structure.
You image is a member of images collection wich is a member of document
object wich is a member of window object:
myWindow.document.images['imageName'].src = url;
or (as it's the only image on the page):
myWindow.document.images[0].src = url;
The trick is though that DOM addressing is not fully available until
the relevant window fires "load" event. So if you do everything in the
row:
...
var myWindow = window.open("data/myFile.html");
alert(myWindow.document.images[0].src);
....
you still may get en error on the second line because images collection
or the whole document will not be fully initialised yet.
If the sole purpose of your popup (which can be blocked btw by a popup
blocker) to show an image why not load the image itself?
<a href="bigOne.jpg" target="myPopup"><img src="smallOne.gif"></a>