admin管理员组

文章数量:1291128

I have some pages running javascript for displaying updates of different measure values. These stuff seems to run fine. But - there is always the risk that javascript can crash in case of a fault (especially after running some hours)

So I want to implement a simple kind of watch dog. One of my ideas is to use a meta-refresh-tag. The Browser will reload the site after xy minutes and all javascripts will be reinitalized.

Of course I do not want to refresh the site if no error occured and want to reset the refresh timer using javascript. As long js runs the timer will be resetted periodally. If javascript crashs the meta-refresh-timer counts down to zero and the page will be reloaded.

Reading stackoverflow postings I have found some answers that says a reset of the meta-timer by javascript is not possible. Do you know a better way to implement the watchdog? Using javascript ittself for refreshing is useless: If the script crashs it will never fire a reload event..

I have some pages running javascript for displaying updates of different measure values. These stuff seems to run fine. But - there is always the risk that javascript can crash in case of a fault (especially after running some hours)

So I want to implement a simple kind of watch dog. One of my ideas is to use a meta-refresh-tag. The Browser will reload the site after xy minutes and all javascripts will be reinitalized.

Of course I do not want to refresh the site if no error occured and want to reset the refresh timer using javascript. As long js runs the timer will be resetted periodally. If javascript crashs the meta-refresh-timer counts down to zero and the page will be reloaded.

Reading stackoverflow postings I have found some answers that says a reset of the meta-timer by javascript is not possible. Do you know a better way to implement the watchdog? Using javascript ittself for refreshing is useless: If the script crashs it will never fire a reload event..

Share Improve this question edited Oct 12, 2024 at 16:07 VLAZ 29.1k9 gold badges62 silver badges84 bronze badges asked Feb 9, 2013 at 11:10 FertFert 811 gold badge1 silver badge3 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

Ideally you should properly handle the error instead of just reloading the page. However you could use the window.onerror event like this:

window.onerror = function() {
    location.reload();
}

More information about onerror here:

https://developer.mozilla/en/docs/DOM/window.onerror

本文标签: Page refresh in case of javascript errorsStack Overflow