Chrome和Firefox的区别:重新加载运行Javascript游戏的页面 [英] Differences between Chrome and Firefox: Reloading a page running a Javascript game

查看:133
本文介绍了Chrome和Firefox的区别:重新加载运行Javascript游戏的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一般的Javascript和网络编程的新手,所以这可能是一个愚蠢的错误。不过,我在查找相关信息时遇到了问题。



我正在用Javascript开发一个游戏,玩家可以通过点击让他们的角色走向不同的建筑物/物体。现在,我只是通过调用 this.gotoTimer = setTimeout(self.location = this.targetURL,1000); 来查找碰撞, / p>

这两个浏览器中的页面链接都很好。问题是当用户按下后退按钮...在Chrome中,一切都重置;玩家在与我在代码中设置的区域相同的区域产生,并且所有的链接目标仍然有效。这是所需的行为。

在Firefox中,一旦后退按钮被按下并且页面重新加载,玩家处于他/她最后的已知位置,并且链接目标访问将不再链接...我可以通过访问它们并按下后退按钮来最终停用它们。



从我已经能够研究的似乎是Firefox对待缓存的一个问题,我已经能够找到的解决方法包括将随机数或时间附加到Javascript文件。这让我感到毛骨悚然。所以我想知道两件事:



    li>这是对问题的准确假设,还是有其他问题?
  1. 如果是这样,追加这些数字的最好方法是什么。整个概念对我来说似乎很不好...
  2. 这么长时间,但我找到了一个解决方案,工作!

    我现在调用
    window.location.reload(true);
    在我打电话给
    的时候window.location = whateverUrl;

    ...我不知道它为什么能很好地工作(我想了一下窗口。 location.reload会重新加载当前的页面,然后去新的[显然不是我想要的]),但似乎很好。这可能是做了一些我不知道我背后的东西,但从功能上来说,它正在做我想做的事情。


    I'm new to Javascript and web programming in general, so this may be a silly mistake. Nevertheless, I've had problems finding information about it.

    I am developing a game in Javascript, where the player can walk around and move from scene to scene by clicking and having their avatar walk to different buildings/objects. For now, I just have the page change location, by calling this.gotoTimer = setTimeout(self.location = this.targetURL, 1000); if a collision is detected.

    The page links fine in both browsers. The problem is when the user presses the back button...In Chrome, everything resets; The player spawns in the same area as I have it set up in code, and all of the 'linktargets' are still valid. This is the desired behavior.

    In Firefox, once the back button is pressed and the page reloads, the player is at his/her last known position, and the linktarget they visited will no longer link...I can eventually deactivate all of them by visiting them and pressing the back button.

    From what I've been able to research, it seems to be a problem with how Firefox treats the cache, and the workaround I've been able to find involves appending a random number or the time to the Javascript files. This strikes me as gross. I may also be way off.

    So I'm wondering two things:

    1. Is this an accurate assumption of the problem, or is there another issue?
    2. If it is, what is the best way to append these numbers. The entire concept seems very hacky to me...

    解决方案

    Sorry to abandon the question for so long, but I found a solution that worked!

    I now call window.location.reload(true); before I call window.location = whateverUrl;

    ...I'm not sure why it works so well (I figured window.location.reload would reload the current page before going to the new one [that obviously isn't what I would want]), but it seems fine. It may be doing something I don't know behind my back I guess, but functionally it is doing what I want.

    这篇关于Chrome和Firefox的区别:重新加载运行Javascript游戏的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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