They probably do save, but at no point in your initiate()
function do you call any of the functions to set the style.
Also, with the way you're setting the values in local storage - every time you select a style from the menu and close the window you're adding an item to the store, here is the call with variables replaced with values:
localStorage.setItem('f3','style3()');
If you do this three times having selected the three different styles then you will simply have three entries in local storage, f1
, f2
and f3
. You never remove any items, so it's hard to see how this is going to help you determine which the last selected style was. What you should be doing is something more like this:
localStorage.setItem('savedStyle','f3');
Then in initiate()
:
var savedStyle = localStorage.getItem('savedStyle');
switch (savedStyle) {
case 'f3':
style3();
break;
case 'f2':
style2();
break;
case 'f1':
default:
style1();
break;
}