简体   繁体   中英

How to store data in localstorage.setItem(); taht we can access anywhere in project

Here I want to store obj.email in localStorage.setItem("PMUsername", obj.email); that I can access in my project anywhere. But I'm not able store the value, it's coming through as null .

window.plugins.googleplus.login({}, function(obj) {
  console.log("Objct", obj);
  //$("#logs").append("<p class='success'><b>response: </b>" +localStorage.setItem("value", JSON.stringify(obj)) + "</p>")
  localStorage.setItem("value", JSON.stringify(obj));

  window.location.href = "login.html";

  document.querySelector("#image").src = obj.imageUrl;
  document.querySelector("#image").style.visibility = 'visible';

  // in below code am displaying email and username value in #feedback i.e <p id="feedback"></p>
  document.querySelector("#feedback").innerHTML = "Hi, " + obj.displayName + ", " + obj.email;
  localStorage.setItem("PMUsername", obj.email);
}, function(msg) {
  $("#logs").append("<p class='error'><b>response: </b>" + msg + "</p>");
});
}

I just need to store that #feedback value in localstorage.getitem() , so that I can access anywhere. Thanks

You cannot set undefined value to the localStorage .

You need to set a string to the localStorage as a value.

For this, your obj should contain property email .

Documentation on localStorage can be helpful.

如果没有收到电子邮件,则无法在localstorage中设置undefined。确保控制台中包含电子邮件(console.log(“ Objct”,obj))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM