i want to make so when I create the TD element for the HTML I want it to stay there after the page refreshes. Right now the element just disappears when I refresh the page. Can someone give me some Tips on how to solve this problem?
if(SkottX == posX && SkottY >= 510){
alert("Your Finale Score is " + Score);
myFunction();
location.reload();
}
function myFunction() {
var table = document.getElementById("table");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "Score:";
cell2.innerHTML = Score;
}
<html>
<head>
<meta charset="UTF-8">
<style>
table, td {
border: 1px solid black;
}
td{
height: 20px;
width: 25px;
}
</style>
</head>
<body onLoad="Initialise()">
<canvas id="myCanvas" width="900" height="600" style="border:10px solid #000070">
</canvas>
<button onclick="gameState = states.RUNNING">Start!</button>
<table id="table" height="900" width="1200" style="display: inline-block">
</table>
<script src="JSgameStarship3.js">
</script>
</body>
</html>
-
1You need to save your data somewhere like a database or the browser localstorageklugjo– klugjo2017年11月30日 09:21:03 +00:00Commented Nov 30, 2017 at 9:21
1 Answer 1
If you only modify the in-memory DOM of the current page, then that is all you will modify.
To persist the changes, you need to explicitly store them.
There are two basic approaches to this:
- Store them somewhere on the client (such as in
localStorage) and use JavaScript to look for the data you stored with the page loads and to reapply the changes if any are found. - Make an HTTP request (e.g. with
XMLHttpRequest) to the server and use server-side code to store the change. If you take this approach, you'll probably want to generate the page using server-side and and data from a database.
answered Nov 30, 2017 at 9:25
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default