0

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>

asked Nov 30, 2017 at 9:19
1
  • 1
    You need to save your data somewhere like a database or the browser localstorage Commented Nov 30, 2017 at 9:21

1 Answer 1

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:

  1. 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.
  2. 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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.