window.mozIndexedDB在Firefox 15中为null [英] window.mozIndexedDB is null in Firefox 15
问题描述
我试图运行 https: //developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB
马上就出现了第一行代码:
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
使用Firebug我发现 window.indexedDB
未定义为预期FF 15,window.webkitIndexedDB未定义为预期(FF不是webkit),但 window.mozIndexedDB
为空,但不是未定义的。如果它是空的,告诉我它存在,但没有一个有效的价值/未初始化。
这是与Firefox 15.0.1在OSX 10.6.8和Ubuntu 12.04。有人可以告诉我为什么我不能看到/使用 window.mozIndexedDB
?我做错了什么?
为了完整性,这里是我的JavaScript文件:
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
var request = window.indexedDB.open(MyTestDatabase,3);
var db;
request.onerror = function(event){
alert(Oops,request.onerror);
};
request.onsuccess = function(event){
//用request.result做些事情!
alert(使之成为request.onsuccess);
db = request.result;
};
//这个事件只在最近的浏览器中实现
request.onupgradeneeded = function(event){
alert(Made it to request.onupgradeneeded);
};
$ b $ db.onerror = function(event){
alert(Database error(db.onerror):+ event.target.errorCode);
};
在添加IndexedDB时,我试图通过浏览器查看文件系统中的文件进行测试。它没有工作,这就是我回到原来的方式,并尝试从Mozilla运行示例代码。
看起来IndexedDB需要一个域,即使它是本地主机。我只是把我的代码放在public_html下,并通过httpd / localhost查看它,它完美的工作。
I'm trying to run the "Using IndexedDB" sample code on https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB
Right out of the gate I stumble with the first line of code:
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
Using Firebug I see that window.indexedDB
is undefined as expected for FF 15, window.webkitIndexedDB is undefined as expected (FF isn't webkit) but window.mozIndexedDB
is null but not undefined. If it's null that tells me it exists but doesn't have a valid value/isn't initialized.
This is with Firefox 15.0.1 on OSX 10.6.8 and Ubuntu 12.04. Can somebody tell me why I'm not able to see/use window.mozIndexedDB
? Am I doing something wrong?
For completeness, here's my JavaScript file:
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
var request = window.indexedDB.open("MyTestDatabase", 3);
var db;
request.onerror = function (event) {
alert("Oops, request.onerror");
};
request.onsuccess = function (event) {
// Do something with request.result!
alert("Made it to request.onsuccess");
db = request.result;
};
// This event is only implemented in recent browsers
request.onupgradeneeded = function (event) {
alert("Made it to request.onupgradeneeded");
};
db.onerror = function (event) {
alert("Database error (db.onerror): " + event.target.errorCode);
};
My original HTML5 application uses jQuery Mobile & REST WS. In development I would run it directly from the file system and it works fine. For sharing with coworkers I have it running behind Apache httpd.
While adding the IndexedDB, I was trying to test by viewing files from the file system via the browser. It didn't work and that's what caused me to go back to square one and try running the example code from Mozilla.
It appears IndexedDB requires a domain even if it's localhost. I simply placed my code under public_html and viewed it via httpd/localhost and it's working perfectly.
这篇关于window.mozIndexedDB在Firefox 15中为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!