versionchange
event is fired when a database structure change (
IDBOpenDBRequest.onupgradeneeded
event or
IDBFactory.deleteDatabase
) was requested.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
事件
|
| 事件处理程序特性 |
onversionchange
|
This example opens a database and, on success, adds a listener to
versionchange
:
// Open the database
const dBOpenRequest = window.indexedDB.open('Nonexistent', 4);
dBOpenRequest.onupgradeneeded = event => {
const db = event.target.result;
// Create an objectStore for this database
const objectStore = db.createObjectStore('toDoList', { keyPath: 'taskTitle' });
// define what data items the objectStore will contain
objectStore.createIndex('hours', 'hours', { unique: false });
objectStore.createIndex('minutes', 'minutes', { unique: false });
objectStore.createIndex('day', 'day', { unique: false });
objectStore.createIndex('month', 'month', { unique: false });
objectStore.createIndex('year', 'year', { unique: false });
};
dBOpenRequest.addEventListener('success', event => {
const db = event.target.result;
db.addEventListener('versionchange', event => {
console.log('The version of this database has changed');
});
});
The same example, using the
onversionchange
事件处理程序特性:
// Open the database
const dBOpenRequest = window.indexedDB.open('Nonexistent', 4);
dBOpenRequest.onupgradeneeded = event => {
const db = event.target.result;
// Create an objectStore for this database
const objectStore = db.createObjectStore('toDoList', { keyPath: 'taskTitle' });
// define what data items the objectStore will contain
objectStore.createIndex('hours', 'hours', { unique: false });
objectStore.createIndex('minutes', 'minutes', { unique: false });
objectStore.createIndex('day', 'day', { unique: false });
objectStore.createIndex('month', 'month', { unique: false });
objectStore.createIndex('year', 'year', { unique: false });
};
dBOpenRequest.onsuccess = event => {
const db = event.target.result;
db.onversionchange = event => {
console.log('The version of this database has changed');
};
};
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
versionchange
event
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 | WebView Android Yes | Chrome Android 25 | Firefox Android 22 | Opera Android 14 | Safari iOS 8 | Samsung Internet Android 1.5 |
完整支持
部分支持
要求使用供应商前缀或不同名称。
onversionchange
event handler property
IDBDatabase
versionchange
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStore
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest