WebOS 在浏览器关闭时重置 LocalStorage?

发布于 2024-10-31 04:54:06 字数 1503 浏览 8 评论 0原文

我有一个 HTML5 Web 应用程序,其中我使用 localStorage 在使用之间保留一些客户端用户设置。我以为我已经一切正常,但我最近发现在 WebOS 浏览器中,本地存储项目在浏览器完全关闭后被清除(所有卡 - 不仅仅是我的页面)。它的行为就像保存到会话存储中一样,但事实并非如此。这是一个说明我的问题的最小示例:

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <meta charset="utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes">
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script>
            $(function() {
                $('#btnV').click(function() {
                    var x = '';
                    for(var i = 0; i < localStorage.length; i++) {
                        x += localStorage.key(i) + ':' + localStorage.getItem(localStorage.key(i)) + '<br/>';
                    }
                    $('#lbl').empty().append(x);
                });
                $('#btnS').click(function() {
                    localStorage.setItem('test', 'blah');
                });
            });
        </script>
    </head>
    <body>
        <span id="lbl"></span>
        <input type="button" id="btnS" value="Save" />
        <input type="button" id="btnV" value="View" />
    </body>
</html>

当我第一次加载页面并单击“查看”按钮时,没有显示任何内容。如果我单击“保存”,然后单击“查看”,我将看到该项目已保存。刷新页面并单击“查看”立即显示该值在页面重新加载期间保留。但是,如果我完全关闭浏览器然后返回页面,“查看”将不会像第一次那样显示任何值。我是否错误地设置了 localStorage 项目,或者我的 WebOS 浏览器是否以某种方式配置为执行此操作?我在设置中找不到任何相关内容。

谢谢...

I have an HTML5 webapp wherein I use localStorage to retain some client-side user settings between uses. I thought I had it all working well, but I recently find that in the WebOS browser the localStorage items are cleared after the browser is completely closed (all cards--not just my page). It is acting like it is saved to session storage, but that is not the case. Here is a minimal example that illustrates my problem:

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <meta charset="utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes">
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script>
            $(function() {
                $('#btnV').click(function() {
                    var x = '';
                    for(var i = 0; i < localStorage.length; i++) {
                        x += localStorage.key(i) + ':' + localStorage.getItem(localStorage.key(i)) + '<br/>';
                    }
                    $('#lbl').empty().append(x);
                });
                $('#btnS').click(function() {
                    localStorage.setItem('test', 'blah');
                });
            });
        </script>
    </head>
    <body>
        <span id="lbl"></span>
        <input type="button" id="btnS" value="Save" />
        <input type="button" id="btnV" value="View" />
    </body>
</html>

When I first load the page and click the "View" button, nothing is shown. If I click "Save" and then "View" I will see the item as saved. Refreshing the page and clicking View immediately shows the value is retained across page-reload. However, if I completely close out the browser and then go back in to the page, "View" will show no values as it did the very first time. Am I setting localStorage items incorrectly, or is my WebOS browser configured somehow to do this? I couldn't find anything relevant in the settings.

Thanks...

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

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

发布评论

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

评论(1

写给空气的情书 2024-11-07 04:54:07

据我所知,WebOS 1.4.x 不支持 localStorage。我想我记得看到它被列为 WebOS 2.0(或者可能是 2.1)中启用的功能,但我找不到有关该主题的任何文档,所以我可能记错了。

假设您存储少量数据,则用户设置通常更适合使用 Mojo.Model.Cookie

在我自己的应用程序中,我使用 cookie 来满足用户首选项,并将应用程序数据存储在 HTML5 数据库中,并使用我的 开源数据库类使HTML5数据库访问更加轻松。

So far as I know, localStorage is not supported in WebOS 1.4.x. I think I remember seeing it listed as a feature that was enabled in WebOS 2.0 (or maybe 2.1), but I cannot find any documentation on the subject, so I could be misremembering.

Assuming you are storing a small amount of data, user settings are usually more appropriately stored in cookies in WebOS using Mojo.Model.Cookie.

In my own app, I use cookies for user preferences, and store the app data in an HTML5 database database, with my open-source database class making the HTML5 database access less onerous.

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