Вопрос

Is there any way to put a html website into the state in was when it loaded (reseting the JS), without actually reloading?

Это было полезно?

Решение

What chris97ong says is partially true. A simple page reload would probably do the trick.

If you are worried about losing specific data you could store it in the session or cookie to prevent losing the data.

I myself have once had this problem whilst making a game in the XNA framework. (A page reload isn't really as easy there...) Anyway, my most simple solution was having a function which replaced all variable values back with their original (starting) values. If you have any animations in your script you'd have to put them back where they started as well. If you do all this in ONE function you could simply call to the function and thereby reset all your JS without actually refreshing.

Tho this solution would probably work, I do feel it's sloppy and a refresh would be the best solution.

Good luck :)

Другие советы

No. It is called onload for a reason, and that is when the page is loaded. There is no way to put the HTML site back to the state it was when it loaded, unless you use location.reload() to reload the page.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top