0

I have an image as follow:
<img id="imgId" src="img/cart.png" style="display: none"/>
When a button is clicked, it calls a JavaScript function to display the image

document.getElementById("imgId").style.display = "inline"

The image is displayed well but it does not show up when I go back from another page.
What I want is after displaying the image, it will be still there even I go to another page and back.
Any helps are appreciated.

1
  • What do you have as a back-end to serve the pages? A little more information would be appreciated. Commented Apr 24, 2011 at 9:21

2 Answers 2

1

You could do it by saving the image "state" in the URL-hash of the page. (The thing after # ).

When displaying the image, do it like this:

document.getElementById("imgId").style.display = "inline";
window.location.hash = "imgIdShown";

And on pageload you run this little piece of code.

if (window.location.hash == "imgIdShown")
{
    document.getElementById("imgId").style.display = "inline";
}
Sign up to request clarification or add additional context in comments.

Comments

0

Save your state in a session if it's possible.

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.