Saving and loading in a HTML game is tricky. You can't just dump some date to the players hard drive, because if you're running in the browser you do not have direct access to the hard drive. There are workarounds.
1. Save/Load as Download/Upload:
Here you setup a save button as an link, and generate the save file on the fly in a on click event
a.href = window.URL.createObjectURL(new Blob( ...) ...)
When the player clicks it he gets a 'download file as...' dialog popup
For loading you use a <input type="file" >
and when the player clicks it, he gets a system default file browser popup, where he can select the file to load. You use window.FileReader.readAsText()
to get the content of the file.
Your save data is usually encoded as json, because it comes right out of the box, but you can make it hard to read using something like base64 encoding (I think Twine does this)
2. Local Storage:
This allows you to store any key-value pair in the browser for any given host. This is somewhere between 2 and 5MB depending on the os and browser. And here's the catch - on Chrome all games/apps run from the hard drive are considered running on the same host, that means that my game, your game, and every twine game in existence share the same 2-5MB - space can run out very fast if you just dump everything into local storage. As far as I know there's no reliable way to tell how much space is left, some browsers simply lie to avoid fingerprinting - so keep in mind that if you are using local storage you might run into problems.
On the other hand - the interface is neat window.localStorage.setItem('who_rulez', 'akabur');
3. IndexedDB:
It's like localStorage only it's a real database. There are still some limits to the size of the data stored, but if your data is too big the browser will usually ask the user to allow for more space. In most cases this won't trigger until you get into a 300MB -100GB range (and if your save is a 100GB, you are doing something wrong!). The interface is not as simple as localStorage, but the real deal-beaker is that it only works if you host your game on a server.