D
Duncan McNiven
I am new to JavaScript. My script works in FireFox (2.0.0.4) but not in
IE (7.0.5730.11 and 6.0.2800.1106) . I have an HTML file that users
open over a LAN. There is no WWW access. The file includes a script
that can automatically reload the page. When the file is missing or
being updated the reload obviously fails. I want to swallow the error
and try again a little later. I don't want the user to see any error
message.
This code works in Firefox:
function wait(msecs)
{
var start = new Date().getTime();
var cur = start;
while (cur-start < msecs)
{
cur = new Date().getTime();
}
}
function doReload()
{
var Reloaded = false;
while (!Reloaded)
{
try
{
location.reload(true);
Reloaded = true;
}
catch(err)
{
wait(500);
}
}
}
wait is not my code. I found it at
http://snippets.dzone.com/posts/show/5828. Oh, and I do realise that I
need code to prevent the while loop running forever if the file never
becomes available. I stripped that out for testing/demo.
IE Says "Internet Explorer cannot display the webpage". I cannot find
any more detailed error message.
I added code to try and display the error details, like this:
catch(err)
{
ErrTxt="doReload error\n\n"
ErrTxt+="Error: " + err.description;
alert(ErrTxt);
wait(500);
}
Firefox describes the error as "undefined". IE Does not display the
alert.
I traced execution in IE's debugger, and found that even when the
location.reload(true); fails (because I deleted the file to be loaded),
IE continues to the next line (Reloaded = true
. I expected an
exception to be thrown so that execution would jump to the catch code,
but that doesn't happen. Why not?
Is my basic approach sensible? If it is, how do I get this working in
IE?
--
IE (7.0.5730.11 and 6.0.2800.1106) . I have an HTML file that users
open over a LAN. There is no WWW access. The file includes a script
that can automatically reload the page. When the file is missing or
being updated the reload obviously fails. I want to swallow the error
and try again a little later. I don't want the user to see any error
message.
This code works in Firefox:
function wait(msecs)
{
var start = new Date().getTime();
var cur = start;
while (cur-start < msecs)
{
cur = new Date().getTime();
}
}
function doReload()
{
var Reloaded = false;
while (!Reloaded)
{
try
{
location.reload(true);
Reloaded = true;
}
catch(err)
{
wait(500);
}
}
}
wait is not my code. I found it at
http://snippets.dzone.com/posts/show/5828. Oh, and I do realise that I
need code to prevent the while loop running forever if the file never
becomes available. I stripped that out for testing/demo.
IE Says "Internet Explorer cannot display the webpage". I cannot find
any more detailed error message.
I added code to try and display the error details, like this:
catch(err)
{
ErrTxt="doReload error\n\n"
ErrTxt+="Error: " + err.description;
alert(ErrTxt);
wait(500);
}
Firefox describes the error as "undefined". IE Does not display the
alert.
I traced execution in IE's debugger, and found that even when the
location.reload(true); fails (because I deleted the file to be loaded),
IE continues to the next line (Reloaded = true
exception to be thrown so that execution would jump to the catch code,
but that doesn't happen. Why not?
Is my basic approach sensible? If it is, how do I get this working in
IE?
--