0

I have a openpopup() to open a popup contains two button yes and no. if visitor click yes then the pop up should be disabled throughout its session.So idea is to set a session variable on click of 'yes' button and get in openpopup() to check if visitor clicked 'yes'. onclick 'yes'

    <input type='button' onclick='abc'>
    <script>
    function abc() {
        $("#divid").hide();
        if (!localStorage['visited']) {
            openpopup();
            localStorage['visited'] = "yes";
        }
    }
    </script>

Issue : I need to set expiration of local storage. plz help

1
  • I would suggest to use SessionStorage instead of LocalStorage, that way your variables will be "cleaned" after every session. LocalStorage is persistent which means it will never be cleaned up unless you handle it. Commented Sep 25, 2013 at 11:10

1 Answer 1

2

You could, instead of storing just a string, store an object in localStorage, like so:

localStorage['visited'] = { value: true, expiration: sometimestamp };

Then of course when checking the value of localStorage['visited'] later, you must verify that the expiration timestamp is still valid:

var v = localStorage['visited'];
if (v.expiration < new Date().getTime())
{
   ...
}
Sign up to request clarification or add additional context in comments.

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.