localStorage和'file:'协议不是持久的,SQLite给出了SECURITY_ERR [英] localStorage and 'file:' protocol not persistent, SQLite gives SECURITY_ERR

查看:285
本文介绍了localStorage和'file:'协议不是持久的,SQLite给出了SECURITY_ERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RapidWeaver - Mac OS X CMS应用程序 - 它不使用服务器环境。它有一个编辑器和一个预览模式。预览模式是基于Webkit的渲染器,我可以像在Safari中一样使用Inspect Element。

I work with RapidWeaver — Mac OS X CMS application — and it uses no server environment. It has an editor and a preview mode. The preview mode is a Webkit based renderer, and I can use 'Inspect Element', like you normally could do in Safari.

我想存储工具栏的一些设置,使用 localStorage或SQLite 。我已经阅读了一些关于indexedDB的信息,虽然我没有找到关于如何使用它的具体实现。

I want to store some settings for a toolbar, either using localStorage or SQLite. I have read some information about indexedDB, though I have found no concrete implementations on how to use it.

localStorage在我保持预览模式时工作正常,当我在编辑器和预览模式之间切换时,url - location.href - 略有改变:

localStorage works fine when I stay in the preview mode, when I switch between editor and preview mode the url — location.href — is slightly altered:

file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-28/RWDocumentPagePreview/code/styled/index.html

file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-29/RWDocumentPagePreview/code/styled/index.html

document-143873968- 28 更改为
document-143873968- 29

document-143873968-28 changes into document-143873968-29

我读到的有关localStorage的内容,它基本上是FireFox的globalStorage [location.hostname]。据我所知,Safari不支持globalStorage,所以我不能尝试。

What I have read about localStorage, that it's basically globalStorage[location.hostname] for FireFox. As far as I know globalStorage is not supported in Safari, so I can't try that.

当我尝试打开数据库时:

When I try to open a database:

var shortName = 'mydatabase';
var version = '1.0';
var displayName = 'My Important Database';
var maxSize = 65536; // in bytes
var db = openDatabase(shortName, version, displayName, maxSize);

我在我的控制台中得到这个:

I get this in my console:

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

这基本上包含了我的问题,我将真诚地感谢任何答案或评论。

That basically wraps up my question, I will appreciate any answers or comments sincerely.

推荐答案

使用以下解决方案:实现WebView数据库配额委托,只需进行一些修改,我就能让它工作。

Using the following solution: Implementing a WebView database quota delegate with a few modifications I was able to get it to work.

以下委托方法对我有用(放在你的webViewDelegate中):

The following delegate method worked for me (place in your webViewDelegate):

- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(id) origin database:(NSString *)databaseIdentifier
{
  static const unsigned long long defaultQuota = 5 * 1024 * 1024;
  if ([origin respondsToSelector: @selector(setQuota:)]) {
    [origin performSelector:@selector(setQuota:) withObject:[NSNumber numberWithLongLong: defaultQuota]];
  } else { 
    NSLog(@"could not increase quota for %@", defaultQuota); 
  }
}

默认情况下,数据库给出0字节,结果在上面的模糊错误消息中。在没有足够空间的情况下尝试创建数据库之后调用上述方法。请注意,此方法在WebUIDelegatePrivate.h中定义( http ://opensource.apple.com/source/WebKit/WebKit-7533.16/mac/WebView/WebUIDelegatePrivate.h )使用可能会阻止您将应用程序提交到mac app store。

By default the database is given 0 bytes, which results in the vague error message you get above. The above method is called after an attempt is made to create a database when there is not enough space. Note that this method is defined in WebUIDelegatePrivate.h ( http://opensource.apple.com/source/WebKit/WebKit-7533.16/mac/WebView/WebUIDelegatePrivate.h ) and using may preclude you from submitting your app to the mac app store.

这篇关于localStorage和'file:'协议不是持久的,SQLite给出了SECURITY_ERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆