window.mozIndexedDB is null in Firefox 15

一笑奈何 提交于 2019-12-10 17:16:06

问题


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);
};

回答1:


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.



来源:https://stackoverflow.com/questions/12770991/window-mozindexeddb-is-null-in-firefox-15

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!