473,396 Members | 2,061 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,396 software developers and data experts.

PopupWindow.document.getElementById() doesn't work for Mozilla?

I have the following code:
var w=window.open('popup.htm','','width=400,height=400 ');

w.opener = this;

var img = w.document.getElementById('pic');

However, the img variable is always null in Mozilla Firefox. But it works
well in IE.

What's teh proper way to access DOM in the popuped window?
Jul 23 '05 #1
2 3105
On Thu, 30 Sep 2004 14:27:12 -0400, nick <nb**************@hotmail.com>
wrote:
I have the following code:
var w=window.open('popup.htm','','width=400,height=400 ');

w.opener = this;
That is unnecessary. The opener property of the new window will refer to
the opening window automatically.
var img = w.document.getElementById('pic');

However, the img variable is always null in Mozilla Firefox. But it
works well in IE.
Have you named the IMG element (that is, name="pic") or given it an id?
Are you sure that the page has loaded before executing the line above?
What's teh proper way to access DOM in the popuped window?


winRef.document.images['image-name-or-id']

is the best way to access images as it will be supported by both old and
new browsers.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
DU
nick wrote:
I have the following code:
var w=window.open('popup.htm','','width=400,height=400 ');

w.opener = this;

Useless and wrong. Avoid coding like that.
var img = w.document.getElementById('pic');

Right here, you're assuming a synchronous chain of event: the window
might be created but the document might still be loading. So you're
referencing the document which has not been loaded yet.
However, the img variable is always null in Mozilla Firefox.
Because the document still has not fired the load event and created
pointers in the memory heap.

But it works well in IE.

What's teh proper way to access DOM in the popuped window?


Get an onload event in the body of the popup window to call a function
in the opener to access the picture. It works reliably in NS 7.x,
Mozilla 1.x, Firefox 0.8+, K-meleon 0.8+, Opera 7.x, MSIE 6 SP2.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.3 :)
Jul 23 '05 #3

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

Similar topics

6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
1
by: chirs | last post by:
Hi, Is there a difference between document.tagID and document.all.tagID. I've seen both like: document.myImage1.src = "nextImage2.jpg" and document.all.hot1.style.color= ... where hot1 is in...
2
by: Gary Mayor | last post by:
Hi, I'm back again. Basically i'm trying to draw a box over an image which is turning out to be a nightmare. The problem i'm getting at the moment is that i'm creating a line with <div which works...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
3
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.