473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.sr c but this does not work. Even
myWindow.img.sr c.URL gives me an undefined so I wonder, is DOM access
of an object I get via "window.ope n" possible at all?

Mar 5 '06 #1
2 1887
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.sr c but this does not work. Even
myWindow.img.sr c.URL gives me an undefined so I wonder, is DOM access
of an object I get via "window.ope n" 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.docume nt.images['imageName'].src = url;
or (as it's the only image on the page):
myWindow.docume nt.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("da ta/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.jp g" target="myPopup "><img src="smallOne.g if"></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.sr c but this does not work. Even
myWindow.img.sr c.URL gives me an undefined so I wonder, is DOM access
of an object I get via "window.ope n" 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
3509
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 window "MyWin" already open, then the main window should load the target url in "MyWin" and not open a new window again.
9
28942
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
5007
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. The server then writes a result cookie into the content destined for the IFRAME. I am having issues accessing the cookie. If I use a debuger I can see the cookie via a quickwatch looking at window.frames.document.cookie however when I run the...
8
5657
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 popWindow=window.open('http://www.yahoo.com','','width=600,height=400,toolbar=1,location=1,menubar=1,resizable=1,titlebar=1,directories=1,status=1,scrollbars=1'); the sidebars are disabled. I click on the buttons for bookmarks and history and they do nothing. I...
3
4229
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 runat=server in those input texts. it works fine with me and i get the result in the third input text. Now when i want to insert the 3 html input text values into my database among other web controls ... i found out that i can't see them unlike web...
18
3349
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 the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I run the code on my local computer but I do have it when I run the code on geocities.
21
18176
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. This has been fine until last week when I started getting javascript 'Permission Denied' errors when I try to access this property. I suspect that a windows update has caused this somehow, as this code has not changed for a very long time. Can...
1
6511
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 iframeID.contentWindow.document for MSIE). This results in an 'access denied' issue in MSIE (No problem in Mozilla). Note that if there is document.domain initialization before this iframe creation/content injection, there is no problem and all works well.
2
3155
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 message as in alert box as " Internet Explorer cannot open the Internet site http://google.citycarrentals.com.au/viewalllocations.php . Operation aborted". It is working in Mozilla . Here i mentioned my code . I am facing this problem several...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.