+ 5
Store Data using JS
Can I store data using JavaScript? So that I can show it with “data:text/html,“?
3 odpowiedzi
+ 3
thank you!
+ 3
so now I wrote this:
<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<script>
// Check browser support
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("highscore", "here!!");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("highscore");
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
</script>
<table>
<th>highscore</th>
<tr>
<td><script> document.write(localStorage.highscore)
</script></td>
</tr>
</table>
</body>
</html>
and at "here" I want to insert the users highscore (I'm making a game) But my webview doesn't read this and it only shows the table header cell: highscores
What could I've done wrong?
+ 1
you can use localStorage and sessionStorage for saving elementary data (key+value)
https://www.w3schools.com/html/html5_webstorage.asp
this is modern browser capabilities.
for save complex data you can use webStorage or indexdb