473,320 Members | 2,145 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.

Problem accessing DOM of window.open result

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?

Mar 5 '06 #1
2 1864
VK

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>

Mar 5 '06 #2
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
Mar 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Samir Pandey | last post by:
Hello, I am using the following javascript code to open a new window. Somehow, IE always opens a new window. It doesn't open target url in the window name given. All i want is, if there is a...
9
by: Sunny | last post by:
Hi, I have cr8ed a javascript function in the head section of a jsp page. <!-- function go(theURL) { alert(theURL); if (theURL!=null){
4
by: Paul Brant | last post by:
Hi all, I have a page with an IFRAME in it. From a script in the main ( parent ) page I instruct the IFRAME to load a specific URL. The URL contains parameters that are processed by the server....
8
by: Dominic Tocci | last post by:
I'm searching for a way to use window.open on my web page to open a window in firefox that allows the sidebars to work (bookmarks, history, etc). When I use the following: var...
3
by: Ali | last post by:
I have 3 html input tex in my asp.net form. Two of them are calling javascript client side to calculate the differnce of two dates and put the result into the third input text. i haven't include...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
21
by: alistair_henderson | last post by:
Morning All, I have some code for a website which uses 'window.open' to simulate modal dialog boxes. I use the window.closed property to decide if the window object exists at various points. ...
1
by: raviviswanathan.81 | last post by:
Hello, So we have a webmaster who sets document.domain to some domain. After that, we try to create and inject text inside an iframe by getting the iframeID.contentDocument (or...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
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
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.