www.webdeveloper.com
Results 1 to 2 of 2

Thread: accessing localstorage using javascript

  1. #1
    Join Date
    May 2013
    Posts
    4

    accessing localstorage using javascript

    I have a requirement where when the user is working on a screen, before the session logs off it saves a message in local storage:

    var userid = self.document.Form1.gsAftlnr.value;
    /* saves the userid in the above variable */
    localStorage.setItem(userid, 'Your previous work was saved in Drafts in the Post Centre.');
    parent.logo.logoff();

    Suppose if the userid = 749461, with this above storage, I am expecting the localstorage the store the string data under key name 749461. Correct me if I am wrong.

    When the user logs in again, I am executing the following code:
    if(localStorage.getItem(userid) !== null)
    { alert(localStorage.getItem(userid)); }
    I want this alert to show up only when the same user logs in again, which is 749461 in this case. But this alert is popping up for other users also.

    Please let me know what I am doing wrong here.

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    if(localStorage.getItem(userid) !== null)
    A simple test reveals that locaStorage.getItem does not return type null for which you are testing.

    Try
    Code:
    if( localStorage.getItem( userid ) )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles