0

I need to store Storageselectedclient even after client logout from my website so that when we logins again the last selected clients will shown up but it's not working also my whole project is in Angular 7.

enter image description here

Here is my working code which has also Idle logout feature in it

  var IDLE_TIMEOUT = 10; //seconds
      var _idleSecondsCounter = 0;

      document.onclick = function () {
          _idleSecondsCounter = 0;
      };

      document.onmousemove = function () {
          _idleSecondsCounter = 0;
      };

      document.onkeypress = function () {
          _idleSecondsCounter = 0;
      };
      $(window).on('hashchange', function(e){
        _idleSecondsCounter = 0;
       });
       window.setInterval(CheckIdleTime, 1000);


      function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
              oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
              localStorage.clear();
              window.location.replace(location.origin);

          }
      } 
4
  • Can you please share the structure of the data you store in localStorage? Commented Jan 20, 2020 at 6:53
  • @HarunYilmaz It's shown in the image Commented Jan 20, 2020 at 6:54
  • Sorry but imgur.com is banned in my country :D Commented Jan 20, 2020 at 6:55
  • You can use localStorage.removeItem('item-key'), for more info => developer.mozilla.org/en-US/docs/Web/API/Window/localStorage Commented Jan 20, 2020 at 6:57

1 Answer 1

4

You can remove the data with removeItem()

localStorage.removeItem('key')

Using clear() will clear all local storage.

localStorage.clear()
Sign up to request clarification or add additional context in comments.

4 Comments

I need to store some object not want to clear whole local storage @HirenMakwana
@UtsavUpadhyay You can use localStorage.setItem("keyName", {}) to store object and localStorage.getItem("keyName") to get object.
apologies but this solution isn't works excatly as i need to store client id so that if someone is autologout after idle time if he logins again last client id is selected
If you have any solution that will be much appreciated and any suggestion although i am going to accept it no issues brother.

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.