Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > PopupWindow.document.getElementById() doesn't work for Mozilla?

Reply
Thread Tools

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

 
 
nick
Guest
Posts: n/a
 
      09-30-2004
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?


 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      09-30-2004
On Thu, 30 Sep 2004 14:27:12 -0400, nick <>
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.
 
Reply With Quote
 
 
 
 
DU
Guest
Posts: n/a
 
      10-01-2004
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
 
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
RE;Kontki if you delete kontiki any program you loaded with it in it 'will not work I have tried it with three programs and none work anymore (if you se it just stop download) 1-Twitch Computer Support 5 04-23-2009 02:45 PM
MS work around on text wrapping in a datagrid does not work TB ASP .Net 2 02-22-2006 10:34 PM
Hi I am new to asp i can not get it to work on xp pro sp2 even though the localhost work but asp pages dont so can some one help craig dicker ASP .Net 9 07-07-2005 11:52 AM
Re: Those cute little "WORK-SAFE" / "NOT WORK-SAFE" tags that people put in the Subject headers of their posts... Soapy Digital Photography 1 08-16-2004 12:07 PM
Re: Those cute little "WORK-SAFE" / "NOT WORK-SAFE" tags that people put in the Subject headers of their posts... Soapy Digital Photography 1 08-16-2004 06:24 AM



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