-1

Currently, I am making a game and when you die, it brings you to the gameover screen which is a separate html file. Underneath the words gameover, I want it to show the players score. The problem is that the score that the player gets is in the first html file. How would I send that score to the other file?

3
  • 1
    I don't understand why you are using an other html file to display just a game over. You can make a div for example , hide it by default and show it when the game is over Commented Jun 24, 2015 at 17:55
  • 1
    It depends on you underlying technology...if you are using java or .net or php or pure html/javascript... Commented Jun 24, 2015 at 17:56
  • @StigCoder04 you can always use a cookie... Commented Jun 24, 2015 at 17:58

2 Answers 2

2

Try using GET variables:

Access GET directly from JavaScript?

This is an easy way to give data to a page from another. You have probably seen its use and haven't noticed it.

The GET variables are passed through the URL, and can be accessed by that page for processing.

Example URL w/ GET variables:

"index.html?score=50&player=joe"

This would pass the score and player variables with the values '50' and 'joe', respectively.

To setup these variables, you just have to append them, as in the example.

The link above is to how to access those variables via javaScript, which would probably be fine for your purposes.

More literature on GET: http://html.net/tutorials/php/lesson10.php

Sign up to request clarification or add additional context in comments.

Comments

2

Assuming the score is saved in javascript, which is most likely, you could just put all your javascript into a .js file and then have your html files use that .js file. For example, you could put all your code in game.js, define the score variable there, and then have both seperate html files use game.js with <script src="game.js"></script>.

Then variables will be usable on both files as both files use the same javascript file.

Comments

Your Answer

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.