Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:07:45+00:00 2026-05-30T22:07:45+00:00

I tried to use following code to test the performance of IndexedDB. The code

  • 0

I tried to use following code to test the performance of IndexedDB.
The code is modified from http://www.html5rocks.com/en/tutorials/indexeddb/todo/ ,
It works well in chrome, but fails in Firefox 10, saying “db.setVersion is not a function”.
I want to know how can I modify the code to make it work in firefox?

        var count=0;
        var MAX=10;
        var times=3;
        var allTime;
        var stime;
        var etime;

        var html5rocks = {};
        var indexedDB = window.indexedDB || window.webkitIndexedDB ||
                        window.mozIndexedDB;

        if ('webkitIndexedDB' in window) {
            window.IDBTransaction = window.webkitIDBTransaction;
            window.IDBKeyRange = window.webkitIDBKeyRange;
        }

        html5rocks.indexedDB = {};
        html5rocks.indexedDB.db = null;

        html5rocks.indexedDB.onerror = function(e) {
            //console.log(e);
            alert("Why didn't you allow my web app to use IndexedDB?!");  
        };

        html5rocks.indexedDB.open = function(type) {

        var request = indexedDB.open("todos");
            request.onsuccess = function(e) {
            var v = "1.20";
            html5rocks.indexedDB.db = e.target.result;
            var db = html5rocks.indexedDB.db;
            // We can only create Object stores in a setVersion transaction;
            if (v!= db.version) {

                var setVrequest = db.setVersion(v);
                // onsuccess is the only place we can create Object Stores
                setVrequest.onerror = html5rocks.indexedDB.onerror;
                setVrequest.onsuccess = function(e) {
                    if(db.objectStoreNames.contains("todo")) {
                        db.deleteObjectStore("todo");
                    }

                    var store = db.createObjectStore("todo",
                        {keyPath: "number"});
                        addTest();
                };

            }
            else addTest();
            };

            request.onerror = html5rocks.indexedDB.onerror;

        }

        html5rocks.indexedDB.addTodo = function(todoText,num) {
            var db = html5rocks.indexedDB.db;
            var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
            var store = trans.objectStore("todo");

            var data = {
            "text": todoText,
            "number": num
            };

            var request = store.put(data);

            request.onsuccess = function(e) {
                count++;
                if(count>=times*MAX)
                {
                    etime=new Date;
                    var t=document.getElementById('result').innerHTML;
                    document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
                    allTime=0;stime=new Date;count=0;
                    getTest();
                }

            };

            request.onerror = function(e) {
            console.log("Error Adding: ", e);
            };
        };

        html5rocks.indexedDB.getTodo = function(id) {
            var db = html5rocks.indexedDB.db;
            var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
            var store = trans.objectStore("todo");

            var request = store.get(id);

            request.onsuccess = function(e) {
                count++;
                if(count>=times*MAX)
                {
                    etime=new Date;
                    var t=document.getElementById('result').innerHTML;
                    document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
                    allTime=0;stime=new Date;count=0;
                    delTest();
                }
            };

            request.onerror = function(e) {
            console.log("Error getting: ", e);
            };
        };

        html5rocks.indexedDB.deleteTodo = function(id) {
            var db = html5rocks.indexedDB.db;
            var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
            var store = trans.objectStore("todo");

            var request = store.delete(id);

            request.onsuccess = function(e) {
                count++;
                if(count>=times*MAX)
                {
                    etime=new Date;
                    var t=document.getElementById('result').innerHTML;
                    document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
                    allTime=0;stime=new Date;count=0;
                    dataTest();
                }
            };

            request.onerror = function(e) {
            console.log("Error Adding: ", e);
            };
        };

        html5rocks.indexedDB.addData = function(d) {
            var db = html5rocks.indexedDB.db;
            var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
            var store = trans.objectStore("todo");
            var data={
                "text":d,
                "number":1
            };
            var request = store.put(data);

            request.onsuccess = function(e) {
                etime=new Date;
                var t=document.getElementById('result').innerHTML;
                document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf()))+"<br/>";
            };

            request.onerror = function(e) {
            console.log("Error Adding: ", e);
            };
        };



        function addTest() {
            for(i=1;i<=times*MAX;i++)
                html5rocks.indexedDB.addTodo('          ',i);
        }
        function getTest() {
            for(i=1;i<=times*MAX;i++)
                html5rocks.indexedDB.getTodo(Math.round(Math.random()*(MAX*times-1)+1));
        }
        function delTest() {
            for(i=1;i<=times*MAX;i++)
                html5rocks.indexedDB.deleteTodo(i);
        }
        function dataTest() {
            data=' ';
            for(i=1;i<=21;i++)
                data=data+data;
            stime=new Date
            html5rocks.indexedDB.addData(data);
        }
        function init() {
            stime=new Date;
            allTime=0;
            html5rocks.indexedDB.open();

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:07:46+00:00Added an answer on May 30, 2026 at 10:07 pm

    The spec is not finalized. This is currently shipped as the property mozIndexedDB in Gecko and webkitIndexedDB in Chrome until the standard is finalized. So you have to write for moz also. Now this code is only for webkit.

    https://developer.mozilla.org/en/IndexedDB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to use the following code to retrieve the data from the
I have tried to use the following code to passing value back from the
I tried the following code in R on windows: library(RCurl) postForm(https://www.google.com/accounts/ClientLogin/, email = me@gmail.com,
Tried following the instructions here: How to use Google app engine with my own
I tried to use the Http Authentication Digest Scheme with my php (apache module)
I have the following code to test memory deallocation using a std::list container: #include
I have the following code that applies a XSLT style Test.Xml.xslTransform = function(xml, xsl)
The following code shows that fields like datetime, float and decimal in my test
I got following code: function test () { this.testFunction = function () { //code
I want to access a model attribute in Javascript. I use the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.