HTML saving & loading

Godot Version

4.3

Question

Hello godoters, i know we can save our games lets say by JSON file in custom folder in appdata, but how about our game being exported to HTML? i want to add game to Crazy Games and i wonder how is it going to be saving, is it going to be working like in normal PC export?

for example this code works perfectly exported normally to Windows, will it be working the same exported to html?

extends Control
var zmienna1="xd" 
var zmienna2="xd"
var zmienna3="xd"
var zmienna4="xd"

func save():
	var save_dict ={
		"zmienna1" : zmienna1, #"zmienna1" is in json file, zmienna1 is our variable
		"zmienna2" : zmienna2,
		"zmienna3" : zmienna3,
		"zmienna4" : zmienna4
	}
	return save_dict

func zapisz_gre():#save game
	var zapisana_gra = FileAccess.open("user://savegame.save", FileAccess.WRITE)
	
	var json_string = JSON.stringify(save())
	
	zapisana_gra.store_line(json_string)



func _on_zapisz_pressed():
	zmienna1=$Panel/zmienna1.liczba
	zmienna2=$Panel/zmienna2.liczba
	zmienna3=$Panel/zmienna3.liczba
	zmienna4=$Panel/zmienna4.liczba
	save()
	zapisz_gre()
	print("zapisano")


func _on_wczytaj_pressed():#load game
	var file: FileAccess = FileAccess.open("user://savegame.save", FileAccess.READ)
	var data: Dictionary = JSON.parse_string(file.get_as_text())
	file.close()
	$zapisane/zmienna1.text = str(data.zmienna1)
	$zapisane/zmienna2.text = str(data.zmienna2)
	$zapisane/zmienna3.text = str(data.zmienna3)
	$zapisane/zmienna4.text = str(data.zmienna4)

Unless you implement server functionality, you won’t be able online.

But, they might be able to save it locally for their own PC session.
Look into LocalStorage and IndexedDB which are common APIs embedded in all modern browsers.

But it’ll be deleted if the user deletes the Cache of his browser or resets browser data.
And you’ll also need to make sure the website allows CORS, or it might block you from accessing LocalStorage, you’ll need to test.

for what i need its perfect solution but where can i read something about it, im seeking and seeking and cant find, is it even on godot docs? a lot of articles about clear html and page creating you know

It’s through using the JavaScript singleton that comes with Godot

Then it’s easy, just use
JavaScript.eval("you put actual JavaScript code here")

And to know the exact JavaScript syntex to put inside there. Search online how to access LocalStorage with JavaScript, since it’s unrelated from Godot, it’s purely JavaScript.

Just know that it works only on browser based games.

thank you very much