I have a javascript animation that uses delay () and setInterval () functions. Everything works fine, but the animation elements become crazy when the user opens another browser tab and returns to the previous tab.
As a solution, I need to reload the page every time the user visits the animation tab again, and the solution seems to be here .
But I see that the overload page only works on localhost. The same code does not work on the remote server, i.e. The page does not reload while revising the page.
Here is the code:
var hidden, visibilityChange; if (typeof document.hidden !== "undefined") { hidden = "hidden"; visibilityChange = "visibilitychange"; } else if (typeof document.msHidden !== "undefined") { hidden = "msHidden"; visibilityChange = "msvisibilitychange"; } else if (typeof document.webkitHidden !== "undefined") { hidden = "webkitHidden"; visibilityChange = "webkitvisibilitychange"; } function handleVisibilityChange() { if (!document[hidden]) {location.reload();} }; document.addEventListener(visibilityChange, handleVisibilityChange, false);
source share