The onclose event handler of the IDBDatabase interface handles the close event, which is fired when the database is unexpectedly closed. This can happen, for example, when the application is shut down or access to the disk the database is stored on is lost while the database is open.
The close event is fired after all transactions have been aborted and the connection has been closed.
Note: This feature is available in Web Workers.
Syntax
IDBDatabase.onclose = function(event) { ... };
Value
A function which is called when the close event is fired.
Example
db.onclose = function(event) {
myAppShowAlert('The database "' + db.name + '" has unexpectedly closed.');
};
Specifications
| Specification | Status | Comment |
| Indexed Database API DraftThe definition of 'onclose' in that specification. | Recommendation |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onclose
|
Chrome Full support 31 Full support 31 Notes' approx |
Edge
Full support ≤18 |
Firefox
Full support 50 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support 10.1 |
WebView Android
Full support Yes |
Chrome Android
Full support 31 |
Firefox Android
Full support 50 |
Opera Android
Full support Yes |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 2.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
See also
- Using IndexedDB
IDBDatabase- close event
IDBDatabase.onclose by Mozilla Contributors is licensed under CC-BY-SA 2.5.