Access DOM of a popup window problem?

N

Nick

I've a main html file which will pop up a window with a image. In the
main Window, I have the following code:

w = window.open('popup.html')
alert(w.document.images.length)

And the alert shows 0.

However, there is a image in the popup window and an
alert(document.images.length) in the popup html file shows 1.

Any suggestion?
 
L

Lasse Reichstein Nielsen

Nick said:
w = window.open('popup.html')
alert(w.document.images.length)

And the alert shows 0.

Ofcourse. The file "popup.html" hasn't even begun to load yet. You'll
have to wait until the page is loaded before you start looking at its
contents.

/L
 
N

Nick

Thanks. I thought the popup finished loading since the open function
return. How to wait? a fix period of time? or better andy
function/variable to tell that?
 
W

Weston C

<i> Thanks. I thought the popup finished loading since the open function
return. How to wait? a fix period of time? or better andy
function/variable to tell that?</i>

Perhaps... you could include an onload event in the body tag of the html
for the popup, which would then set a variable related to the parent
window. Meanwhile, the script running in the parent window could check
every second or so to see if that variable had been set...

~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.org
(remove eights to email me)
 
N

Nick

Thanks, I also thought about similar method. But it's so cumbersome....
Had to put the code in the popup html code. Don't know why the W3C not
expand it because it's so important a feature.
 
M

Michael Winter

[Fixed and snipped top-post]
Weston C wrote:
[snip]
Perhaps... you could include an onload event in the body tag of the
html for the popup, which would then set a variable related to the
parent window. Meanwhile, the script running in the parent window
could check every second or so to see if that variable had been
set...
[snip]

Thanks, I also thought about similar method. But it's so cumbersome....
Had to put the code in the popup html code. Don't know why the W3C not
expand it because it's so important a feature.

Considering that the W3C discourage pop-ups on the basis of reduced
accessibility, that isn't going to happen in the near future.

Mike
 
D

DU

Weston said:
<i> Thanks. I thought the popup finished loading since the open function
return. How to wait? a fix period of time? or better andy
function/variable to tell that?</i>

Perhaps... you could include an onload event in the body tag of the html
for the popup, which would then set a variable related to the parent
window. Meanwhile, the script running in the parent window could check
every second or so to see if that variable had been set...

~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.org
(remove eights to email me)


Well, I'm happy to read your post because this is almost exactly what I
do :) in this page:

Create a sub-window and dynamically DOM-insert an image
http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/DynamicInsertionDOMImageInPopup.html

DU
 
G

Grant Wagner

Don't keep a script running in the opener waiting for a state change, that's
silly (and cumbersome). Just have the state change of the popup trigger a
handler function in the opener.

<!-- in OPENER -->
var w = window.open('popup.html');
function wIsNowOpen(message) {
alert(message);
}

<!-- in popup.html -->
<body onload="call_wIsNowOpen();">
<script type="text/javascript">
function call_wIsNowOpen() {
if (window.opener && window.opener.wIsNowOpen) {
window.opener.wIsNowOpen('w is now open');
}
}
</script>
Thanks, I also thought about similar method. But it's so cumbersome....
Had to put the code in the popup html code. Don't know why the W3C not
expand it because it's so important a feature.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top