blocked
handler is executed when an open connection to a database is blocking a
versionchange
transaction on the same database.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
IDBVersionChangeEvent
|
| 事件处理程序特性 |
onblocked
|
使用
addEventListener()
:
// Open the database
const DBOpenRequest = window.indexedDB.open('toDoList', 4);
DBOpenRequest.onupgradeneeded = (event) => {
const db = event.target.result;
db.onerror = () => {
console.log('Error creating database');
};
// Create an objectStore for this database
var 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) => {
// Let's try to open the same database with a higher revision version
const req2 = indexedDB.open('toDoList', 5);
// In this case the onblocked handler will be executed
req2.addEventListener('blocked', () => {
console.log('Request was blocked');
});
};
使用
onblocked
特性:
// Open the database
const DBOpenRequest = window.indexedDB.open('toDoList', 4);
DBOpenRequest.onupgradeneeded = (event) => {
const db = event.target.result;
db.onerror = () => {
console.log('Error creating database');
};
// Create an objectStore for this database
var 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) => {
// Let's try to open the same database with a higher revision version
const req2 = indexedDB.open('toDoList', 5);
// In this case the onblocked handler will be executed
req2.onblocked = () => {
console.log('Request was blocked');
};
};
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
blocked
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
|
完整支持
部分支持
要求使用供应商前缀或不同名称。
onblocked
event handler property
IDBOpenDBRequest
blocked
upgradeneeded
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStore
IDBObjectStoreSync
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest