cfs_quota
I've been working on an HTML5 application for the new , writing a tutorial along the way to help all of you create and promote your HTML5 web-powered app. The HTML5 app uses localStorage to save basic search history, as well as other newer APIs. While testing my application on my iPhone, I was seeing the following error:
我一直在为新的 HTML5应用程序,并在编写教程的过程中帮助所有人创建和推广HTML5网络驱动的应用程序。 HTML5应用程序使用localStorage来保存基本搜索历史记录以及其他较新的API。 在iPhone上测试应用程序时,出现以下错误:
localStorage.setItem("history", JSON.stringify(myObject));
The error caused my app to break, refreshing the page and rendering the app useless! After a bit of research, I found that the reason for the error was that my Mobile Safari's Private Browsing was turned on. You'd expect a silent error when this mode is one, but nope -- simply a bricked app. Since there's no way to detect if the user's browser is in "Private Browsing" is turned on (feature detection still works), the best solution is to wrap localStorage setters in try {} / catch() {}
blocks:
该错误导致我的应用程序损坏,刷新页面并使该应用程序无用! 经过一番研究,我发现该错误的原因是我的Mobile Safari的“私人浏览”已打开。 当这种模式是一种模式时,您会期待一个无声的错误,但不是-仅仅是一个砖砌的应用程序。 由于无法检测用户的浏览器是否处于“私人浏览”状态(功能检测仍然有效),因此最好的解决方案是将localStorage设置器包装在try {} / catch() {}
块中:
try { localStorage.setItem("history", JSON.stringify(myObject));}catch(e) {}
I'm not seeing a better solution at the moment. Since there's now way to track Private Mode, and certain interactions break in this mode, using try {} / catch() {}
blocks appears to be the best solution.
我目前没有更好的解决方案。 由于现在有了跟踪专用模式的方法,并且某些交互在此模式下中断,因此使用try {} / catch() {}
块似乎是最好的解决方案。
翻译自:
cfs_quota