Page Refresh for JavaScript Errors

I have several pages running javascript to display updates of different values. These things seem to be working fine. But - there is always a risk that javascript may crash in the event of a crash (especially after a few hours).

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

Of course, I do not want to update the site if there is no error, and I want to reset the update timer using javascript. As js starts, the timer will periodically restart. If javascript fails, meta-refresh-timer counts down to zero and the page will reload.

Reading stacking messages in a stream I found several answers that say that resetting the javascript meta-timer is not possible. Do you know the best way to implement a watchdog timer? Using javascript ittself to update is useless: if the script fails, it will never fire a reload event.

+4
source share
1 answer

Ideally, you should handle the error correctly, and not just reload the page. However, you can use the window.onerror event as follows:

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

More about onerror here:

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

0
source

All Articles