Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

IDBFactory.open()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

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

文档标签和贡献者

 此页面的贡献者: jpmedley, fscholz, chrisdavidmills
 最后编辑者: jpmedley,