I would like to save data or values like with html and use them again when the page is called up again. I have here an example from https://www.w3schools.com/html/html5_webstorage.asp how it works in html, does the whole thing also work in blazor?
function clickCounter() {
if (typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " + localStorage.clickcount + " time(s).";
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
</body>
</html>
In reality Blazor can only access the browser local storage via JavaScript - WASM doesn't have access directly.
However it's much easier if you use a library such as https://github.com/Blazored/LocalStorage - this will provide the necessary JS and can be injected as a service.