location.reload()在远程服务器上不起作用 [英] location.reload() doesn't work on remote server

查看:288
本文介绍了location.reload()在远程服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript动画,它使用delay()和setInterval()函数.一切正常,但是当用户打开另一个浏览器选项卡并返回上一个选项卡时,动画元素会变得疯狂.

I have a javascript animation which uses delay() and setInterval() functions. Everything works fine but animation elements become crazy when user opens another browser tab and goes back to the previous tab.

作为解决方案,每次用户再次访问动画选项卡时,我都需要重新加载页面,看来解决方案是

As a solution I need to reload the page each time a user is visited the animation tab again and it seems the solution is here.

但是我看到重新加载页面仅在localhost上有效.相同的代码在远程服务器上不起作用,即无法通过重新访问页面来重新加载页面.

But I see that reloading page works only on localhost. The same code doesn't work on remote server i.e. page is not reloaded by revisiting the page.

这是代码:

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);

推荐答案

我无法解释,但似乎解决方案是

I cannot explain, but it seems that soluton is

location.href = location.href;

代替

location.reload();

页面已重新加载到本地和远程服务器上.

The page is reloaded on local and remote server.

这篇关于location.reload()在远程服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆