I had this issue too. I did pretty much like you did, but instead of using webstorage, I used a dictionary. Then I created a function called resetGlobals(), in which I first copy the variables I want to keep into the dictionary, then reset the global variables, and finally copy back the values from the dictionary to the global variables. Then I just call this function whenever I need it, like when changing layout.
Having everything in one function is easier to maintain, especially if you want to add more variables later (score, sound volume, language...)