469,936 Members | 2,405 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

when is my window ready ?

It seems as though when I use window.open I can't immediately do

winId.document.getElementById("someDivTagInTheWind ow")

because window.open returns to my code before the html in the window
is really loaded.

What is a good way to synchronize, in other words to have my code know
when the window is ready to be interrogated ?

Thanks. er*******@rcn.com
Jul 23 '05 #1
4 7227
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...

What is a good way to synchronize, in other words to have my code know
when the window is ready to be interrogated ?


Have the new window run script onLoad telling opener that it loaded.

--
--
~kaeli~
I can't sleep.
The clowns might eat me.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...

What is a good way to synchronize, in other words to have my code know
when the window is ready to be interrogated ?


Have the new window run script onLoad telling opener that it loaded.

--

What are you proposing as an easy way for "telling opener" . If I
put

<body onLoad="HiImReady();">

the HiImReady function has to be in the html running in the new
window, but how can I call a function back in the html whose script
did the window.open ? (or did you mean something else entirely ???)
Jul 23 '05 #3
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...

What is a good way to synchronize, in other words to have my code know
when the window is ready to be interrogated ?


Have the new window run script onLoad telling opener that it loaded.

--

What are you proposing as an easy way for "telling opener" . If I
put

<body onLoad="HiImReady();">

the HiImReady function has to be in the html running in the new
window, but how can I call a function back in the html whose script
did the window.open ? (or did you mean something else entirely ???)


The opener has a global variable. Call it childIsOpen.

var childIsOpen = false;

The opener has a function to set that variable. Call it setChildIsOpen.
function setChildIsOpen(b)
{
childIsOpen = b;
return;
}

The child then tells the opener it loaded.
<body onLoad="window.opener.setChildIsOpen(true)">

The opener can then test that variable as
if (childIsOpen)
{
// whatever
}

Works in theory.

Let me test it and see...
Okay, this worked fine in IE. Test in any other browsers you'd like.

----------------------------------
test3.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
var childIsOpen = false;

function setChildIsOpen(b)
{
childIsOpen = b;
return;
}

function openChild()
{
window.open("test4.html","","toolbars=no,width=100 ,height=100");
setTimeout("testChild()",1000);
}

function testChild()
{
if (childIsOpen)
alert("open!");
else
alert("nope!");
}
</script>
</head>

<body>
<form>
<input type="button" value="Click to open" onClick="openChild()">
</form>
</body>
</html>

-------------------------------

test4.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
</script>
</head>

<body onLoad="window.opener.setChildIsOpen(true)">
test
</body>
</html>
--
--
~kaeli~
The man who fell into an upholstery machine is fully
recovered.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <39**************************@posting.google.com >,
er*******@rcn.com enlightened us with...
>
> What is a good way to synchronize, in other words to have my code know
> when the window is ready to be interrogated ?
>
>

Have the new window run script onLoad telling opener that it loaded.

--

What are you proposing as an easy way for "telling opener" . If I
put

<body onLoad="HiImReady();">

the HiImReady function has to be in the html running in the new
window, but how can I call a function back in the html whose script
did the window.open ? (or did you mean something else entirely ???)


The opener has a global variable. Call it childIsOpen.

var childIsOpen = false;

The opener has a function to set that variable. Call it setChildIsOpen.
function setChildIsOpen(b)
{
childIsOpen = b;
return;
}

The child then tells the opener it loaded.
<body onLoad="window.opener.setChildIsOpen(true)">

The opener can then test that variable as
if (childIsOpen)
{
// whatever
}

Works in theory.

Let me test it and see...
Okay, this worked fine in IE. Test in any other browsers you'd like.

----------------------------------
test3.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
var childIsOpen = false;

function setChildIsOpen(b)
{
childIsOpen = b;
return;
}

function openChild()
{
window.open("test4.html","","toolbars=no,width=100 ,height=100");
setTimeout("testChild()",1000);
}

function testChild()
{
if (childIsOpen)
alert("open!");
else
alert("nope!");
}
</script>
</head>

<body>
<form>
<input type="button" value="Click to open" onClick="openChild()">
</form>
</body>
</html>

-------------------------------

test4.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
</script>
</head>

<body onLoad="window.opener.setChildIsOpen(true)">
test
</body>
</html>
--

Thanks for doing that !

The crux which I seemed to have been missing before is the whole
ability to have the script in the new window have the ability to
"reach back" into its caller space by saying

window.opener ...

That's a real eye opener.

Thanks.

/Eric
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Coral Snake | last post: by
2 posts views Thread by Reply Via Newsgroup | last post: by
3 posts views Thread by Christopher Benson-Manica | last post: by
31 posts views Thread by Benno Bös | last post: by
4 posts views Thread by Chuck Tomasi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.