向用户公开的本地存储

发布于 2024-09-28 22:20:30 字数 50 浏览 3 评论 0原文

用户是否可以查看使用 localStorage API 存储的项目的值?就像饼干一样?

Are the values of items stored using the localStorage API viewable by users? Just like cookies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲欢浪云 2024-10-05 22:20:30

Safari 和 Chrome 的网络检查器允许检查该数据,是的。我不确定其他浏览器如何处理它,但它肯定不是您可以依赖的不被编辑的东西。

Safari and Chrome's web inspector allows inspection of that data, yes. I'm not sure how other browsers handle it, but it's certainly not something you can depend on not being edited.

拥醉 2024-10-05 22:20:30

您可以轻松加载要向用户显示的项目。

只需在页面加载时使用 Javascript 循环遍历本地存储中的所有项目...

<body>
<script language="JavaScript" type="text/javascript">
var item = "";//array to hold string values for each key value
var key ="";//array to hold string values for each key name
for (i=0;i < localStorage.length;i++) {

    var count = 0;
    if (key != "" | key != null) { //or matches what you're looking for
      item[count] = localStorage.getItem(key);
      key(i) = localStorage.key(i);
      count += 1;
    }

 }

function load_table()
{
if (item == "" || item == " " || item == null) {
document.write("<div id=\"list_table\" style=\"display: block;\">");
document.write("<h3>You have no stored items.</h3>");
document.write("</div>");
}
else {
     document.write("<div id=\"list_table\" style=\"display: block;\">");
     document.write("<h3>Stored Items</h3>");
     document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");

     for (i=0;i < item.length;i++) {
          document.write("<tr><td width=\"33%\" valign=\"top\">"+item(i)+"</td>");
          document.write("<td width=\"67%\" valign=\"top\" style=\"padding-left: 0px; text-transform: capitalize;\">"+key(i)+"</td></tr>");
          }
 }


document.write("</table>");
document.write("</div> <!-- end list_table div -->");
} // end if (item != "")
} // end load_table
</script>

在 html 中,您将一个可以显示或隐藏的 div 粘贴在适当的位置。

<div id="items_table" style="display: none;">
<script language="JavaScript" type="text/javascript">
//alert("calling load_table");
load_table();
//alert("DONE calling load_table");
</script>
</div>

如果他们单击链接,您就可以显示在页面加载期间填充并隐藏的 items_table。只要您没有加载数千个项目,它就会快速加载。

如果您愿意,我可以挖掘一个链接,用于在样式显示属性的块和无之间切换显示。

You can easily load the items to be displayed to users.

Just loop through all the items in local storage using Javascript as the page loads...

<body>
<script language="JavaScript" type="text/javascript">
var item = "";//array to hold string values for each key value
var key ="";//array to hold string values for each key name
for (i=0;i < localStorage.length;i++) {

    var count = 0;
    if (key != "" | key != null) { //or matches what you're looking for
      item[count] = localStorage.getItem(key);
      key(i) = localStorage.key(i);
      count += 1;
    }

 }

function load_table()
{
if (item == "" || item == " " || item == null) {
document.write("<div id=\"list_table\" style=\"display: block;\">");
document.write("<h3>You have no stored items.</h3>");
document.write("</div>");
}
else {
     document.write("<div id=\"list_table\" style=\"display: block;\">");
     document.write("<h3>Stored Items</h3>");
     document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");

     for (i=0;i < item.length;i++) {
          document.write("<tr><td width=\"33%\" valign=\"top\">"+item(i)+"</td>");
          document.write("<td width=\"67%\" valign=\"top\" style=\"padding-left: 0px; text-transform: capitalize;\">"+key(i)+"</td></tr>");
          }
 }


document.write("</table>");
document.write("</div> <!-- end list_table div -->");
} // end if (item != "")
} // end load_table
</script>

In the html, you stick a div that can be shown or hidden, in an appropriate place.

<div id="items_table" style="display: none;">
<script language="JavaScript" type="text/javascript">
//alert("calling load_table");
load_table();
//alert("DONE calling load_table");
</script>
</div>

If they click a link, you can then display items_table that is populated during page load, and hidden. So long as you don't have thousands of items to load, it loads quickly.

I can dig up a link to toggling the display between block and none for the style display property if you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文