I am writing a game and use different html files but only one javascript file, which is included in every html file. I have my global variables in this file that are necessary for the game run. I have access and can change the variables from all over the html files which I am switching with , but for one thing I use javascript to change the page, because I need to differ either the game is over or a new round starts.
I use
if (...) {document.location.href = "end.html"}
else {document.location.href = "newround.html}
The changing actually works, but the thing is that after this change it resets ALL global variables in the JavaScript file, which is bad because I need some of those in the new rounds.. I cannot find anything helpful on the web, so please help me out, I really need this! :(
Thanks!
What Matt said is right. If you want to preserve state between pages:
您可以将iframe
用作游戏容器。
Personally, I had issues with this too. My workaround ended up being that I had to save the changed variables server-side. I utilize a session manager (Redis) to save the last saved variables. When the page directs to "end.html" or "newround.html", recall the last saved variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.