W3cubDocs

/DOM

IDBFactory.open-obsolete

Warning: This method comes from an older version of the standard, which is still implemented in some browsers. For modern browsers you should use the newer IDBFactory.open with two parameters, name and version. See the compatibility table for more information on what browsers support what method.

The original, now obsolete open() method of the IDBFactory object requests opening a connection to a database. The method returns an IDBRequest object immediately, and performs the open operation asynchronously. If the operation is successful, a success event is fired on the request object returned from this method, with its result attribute set to the new IDBDatabase object for the connection.

If an error occurs while the database connection is being opened, then an error event is fired on the request object returned from this method.

Syntax

var request = window.indexedDB.open("toDoList");

Returns

A IDBRequest object on which subsequent events related to this request are fired.

Example

var DBOpenRequest = window.indexedDB.open("toDoList");

DBOpenRequest.onerror = function(event) {
  console.log("Error loading database.");
};
 
DBOpenRequest.onsuccess = function(event) {
  console.log("Database initialised");
    
  // store the result of opening the database in the db variable. This is used a lot later on, for opening transactions and suchlike.
  db = request.result;
};

Parameters

name
The name of the database.

Specifications

This version of the open() method is from an old version of the spec. The latest version is specified at the link below:

Specification Status Comment
Indexed Database API
The definition of 'open()' in that specification.
Editor's Draft

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 23webkit
24
10 moz
16.0 (16.0)
10, partial 15 7.1
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support 4.4 22.0 (22.0) 1.0.1 10 22 No support

See also

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open-obsolete