Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem accessing DOM of window.open result

Reply
Thread Tools

Problem accessing DOM of window.open result

 
 
DOM_scripter
Guest
Posts: n/a
 
      03-05-2006
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?

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      03-05-2006

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>

 
Reply With Quote
 
 
 
 
Gérard Talbot
Guest
Posts: n/a
 
      03-05-2006
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?


Posting an url helps readers reading posts and helps them trying to
figure out what may be wrong in a page or set of pages.
For instance, we have no idea how you declare myWindow nor how you make
the call to change the src attribute.

You can modify the src attribute of a secondary window

1- assuming that the cross-domain security restrictions do not apply and

2- assuming that the document objects have been loaded in the document
when the access to the image is done. You must know that window object
and document object are created and loaded asynchronously.

For 1:
http://developer.mozilla.org/en/docs...and_parameters

For 2:
http://developer.mozilla.org/en/docs...en#Description

I have working examples of changing the src attribute of an image in a
secondary window.

Gérard
--
remove blah to email me
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i = 10; result = ++i - --i; How result become ZERO Lakshmi Sreekanth C Programming 52 09-23-2010 07:41 AM
Re: i = 10; result = ++i - --i; How result become ZERO Mr. Buffoon C Programming 4 09-23-2010 03:01 AM
Is the result of valid dynamic cast always equal to the result ofcorrespondent static cast? Pavel C++ 7 09-18-2010 11:35 PM
simulation result is correct but synthesis result is not correct J.Ram VHDL 7 12-03-2008 01:26 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57