null or not an object using frames

P

Phoenix

I have a site that is supposed to be 'real-time' which has a frameset
of 2 rows (the bottom row is 1 pixel so essentially invisible to IE
users which is the requirement for the product). The bottom frame
refreshes using an http-refresh every 15 seconds. If new data is
available on the server, it tells the top page to refresh. For checks
and balances, the top frame has a form at the bottom of the page with a
'clockBox'..which is essentially a text box that gets updated every
second so it looks like a timer. When the bottom frame refreshes, it
waits 5 seconds then resets the top counter to 0. The top counter
continues to count. If the top counter gets to 30 (which it never
should unless the bottom frame gets stuck), it refreshes the bottom
frame.

My problem:
When the top frame is taking too long to load, I get a javascript
error:
Error: 'window.parent.frames.body.coutnerFomr.clockBox' is null or not
an object.

Here's my code:

<script language="javascript">
timer = setTimeout("setCounter()",8000);
function setCounter(){
if (window.parent.frames["body"].counterForm.clockBox){
window.parent.frames["body"].counterForm.clockBox.value = 0;
}
}
</script>
 
S

Stephen Chalmers

Phoenix said:
I have a site that is supposed to be 'real-time' which has a frameset
of 2 rows (the bottom row is 1 pixel so essentially invisible to IE
users which is the requirement for the product). The bottom frame
refreshes using an http-refresh every 15 seconds. If new data is
available on the server, it tells the top page to refresh. For checks
and balances, the top frame has a form at the bottom of the page with a
'clockBox'..which is essentially a text box that gets updated every
second so it looks like a timer. When the bottom frame refreshes, it
waits 5 seconds then resets the top counter to 0. The top counter
continues to count. If the top counter gets to 30 (which it never
should unless the bottom frame gets stuck), it refreshes the bottom
frame.

My problem:
When the top frame is taking too long to load, I get a javascript
error:
Error: 'window.parent.frames.body.coutnerFomr.clockBox' is null or not
an object.

Here's my code:

<script language="javascript">
timer = setTimeout("setCounter()",8000);
function setCounter(){
if (window.parent.frames["body"].counterForm.clockBox){
window.parent.frames["body"].counterForm.clockBox.value = 0;
}
}
</script>

I suspect that's because window.parent.frames["body"].counterForm.clockBox
cannot be an object until window.parent.frames["body"] is loaded.

Instead of waiting a fixed time, it may be better to monitor continuously
until the other frame's document is loaded.

[Not tested]

timer = setInterval("setCounter()",500);

function setCounter()
{
if (window.parent.frames["body"] &&
window.parent.frames["body"].counterForm.clockBox)
{
clearInterval(timer);
window.parent.frames["body"].counterForm.clockBox.value = 0;
}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top