Javascript 我如何像 FT 网络应用程序一样请求增加 iPad 上的 HTML5 本地存储大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6276282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I request an increase to the HTML5 localstorage size on iPad, like the FT web app does?
提问by FrancescoR
If you open http://app.ft.com(the Financial Times mobile web app), you are prompted to add the app to your "home".
如果您打开http://app.ft.com(金融时报移动网络应用程序),系统会提示您将该应用程序添加到您的“家”。
After doing this, when you open the app, you are prompted again to allow the localstoreage database size to be increased up to 50MB.
执行此操作后,当您打开应用程序时,系统会再次提示您允许将 localstoreage 数据库大小增加到 50MB。
- How can this be done? Is there some JavaScript API call? Permissions or whatever?
- Is this iPad (iOS?) specific, or does it work on other Webkit browsers?
- 如何才能做到这一点?是否有一些 JavaScript API 调用?权限还是什么?
- 这个 iPad (iOS?) 是特定的,还是可以在其他 Webkit 浏览器上使用?
回答by Rowan
I happen to know something about this ;)
我碰巧对此有所了解;)
There's no API for requesting an increase in storage size for an existing database. There is one way to force an increase: write data to the database in such a size that an increase is required, prompting the user. However, this would be slow andthere's no way to tell the currently allocated space, so it's not recommended.
没有用于请求增加现有数据库存储大小的 API。有一种强制增加的方法:将数据以需要增加的大小写入数据库,提示用户。但是,这会很慢,并且无法告诉当前分配的空间,因此不建议这样做。
Black Frog has part of this correct: the only neat way to do this is to request a very large database when it is opened, for example:
Black Frog 有一部分是正确的:唯一巧妙的方法是在打开时请求一个非常大的数据库,例如:
openDatabase('databaseName', '1.0', 'My Database', 50*1024*1024, …
… to request 50MB of space.
...请求 50MB 的空间。
However, when the user first visits the site, you may not want to prompt them about a 50MB limit at once; so you might think that you could ask for 5MB at first, and then later re-open it with 50MB? Unfortunately, this doesn't work - the second open attempt, with an increased quantity, succeeds silently, not prompting for a size increase and not actually increasing the available size.
但是,当用户第一次访问该站点时,您可能不想一次提示他们 50MB 的限制;所以你可能认为你可以先要求 5MB,然后再用 50MB 重新打开它?不幸的是,这不起作用 - 第二次打开尝试,增加数量,默默地成功,不提示增加大小,实际上也没有增加可用大小。
The FT app therefore starts off with a 5MB "preview" database, so that the user isn't prompted on first load. It tries not to exceed this 5MB limit, as any space assigned has to be shared across all databases.
因此,FT 应用程序从一个 5MB 的“预览”数据库开始,以便在首次加载时不会提示用户。它尽量不超过这个 5MB 的限制,因为任何分配的空间都必须在所有数据库之间共享。
If the user chooses to allow storage of more content, the app then tries to open a database with a different name with 40MB of space (for which the user is prompted to approve 50MB). This allows 40MB in that database, and 5MB in the original preview database, so neither should fail when inserting rows - as 50MB total is currently the limit on iOS.
如果用户选择允许存储更多内容,应用程序将尝试打开一个具有 40MB 空间的不同名称的数据库(提示用户批准 50MB)。这允许该数据库中有 40MB,原始预览数据库中有 5MB,因此在插入行时都不会失败 - 因为 50MB 目前是 iOS 上的限制。
All browsers currently handle database space limits differently, so if you're planning cross-platform, test carefully. Desktop Safari handles it rather nicely, allowing much larger; Chrome doesn't allow any increase at all; etc. Expect all "HTML5" implementations to differ in strange ways :)
所有浏览器当前处理数据库空间限制的方式不同,因此如果您计划跨平台,请仔细测试。Desktop Safari 处理得相当好,允许更大;Chrome 根本不允许任何增加;等等。希望所有“HTML5”实现都以奇怪的方式不同:)
回答by Black Frog
This database is part of Web SQL DatabaseAPI, which is not part of HTML5. Use the following the set the size of your database
此数据库是Web SQL 数据库API 的一部分,而不是 HTML5 的一部分。使用以下设置你的数据库的大小
function prepareDatabase(ready, error) {
return openDatabase('documents', '1.0', 'Offline document storage', 50*1024*1024, function (db) {
db.changeVersion('', '1.0', function (t) {
t.executeSql('CREATE TABLE docids (id, name)');
}, error);
});
}
Introducing Web SQL Databaseson HTML5 Doctor has a very quick tutorial on how all of this works.
Introducing Web SQL Databaseson HTML5 Doctor 有一个关于所有这些如何工作的非常快速的教程。
回答by user1258024
I just tested with my offline app in iPad 2( iOS 5.1.1) that we do not need to do anything specific inside the app. For e.g., my app has about 18 MB of offline data. When the browser hit URL, browser popped up the message requesting increase in size to 25 MB and I accepted it and all is fine. Thanks
我刚刚在 iPad 2(iOS 5.1.1)中使用我的离线应用程序进行了测试,我们不需要在应用程序内部执行任何特定操作。例如,我的应用程序有大约 18 MB 的离线数据。当浏览器点击 URL 时,浏览器弹出消息要求将大小增加到 25 MB,我接受了它,一切都很好。谢谢
回答by Ian Devlin
It's browser specific. Most have set it to 5MB and some give the option of increasing it through a setting somewhere. Not all browsers offer this though.
它是特定于浏览器的。大多数人将其设置为 5MB,有些人可以选择通过某处的设置来增加它。并非所有浏览器都提供此功能。
回答by Paul D. Waite
Huh — Dive into HTML5 says that no browser supported this as of February 2011, so I guess this might be an iOS 4.3 thing? (iOS 4.3 shipped in March 2011.)
嗯——深入 HTML5 说截至 2011 年 2 月没有浏览器支持这个,所以我猜这可能是 iOS 4.3 的东西?(iOS 4.3 于 2011 年 3 月发布。)
I can't find any references to it from a quick Google. Apple's own developer documentation might mention it — I'm not sure if that's available to non-SDK subscribers though.
我无法从快速谷歌中找到任何对它的引用。Apple 自己的开发人员文档可能会提到它——不过我不确定它是否适用于非 SDK 订阅者。