Back to Content

IDBVersionChangeEvent: IDBVersionChangeEvent() constructor

files/en-us/web/api/idbversionchangeevent/idbversionchangeevent/index.md

latest1.4 KB
Original Source

{{securecontext_header}}{{APIRef("IndexedDB")}}

The IDBVersionChangeEvent() constructor creates a new {{domxref("IDBVersionChangeEvent")}} object, which is used to represent when a version of the database has changed, as a result of the {{domxref('IDBOpenDBRequest.upgradeneeded_event', 'onupgradeneeded')}} event handler.

Syntax

js-nolint
new IDBVersionChangeEvent(type)
new IDBVersionChangeEvent(type, options)

Parameters

  • type
    • : A string with the name of the event. It is case-sensitive and browsers set it to versionchange, success, or blocked.
  • options {{optional_inline}}
    • : An object that, in addition of the properties defined in {{domxref("Event/Event", "Event()")}}, can have the following properties:
      • oldVersion {{optional_inline}}
        • : A number representing the previous version of the database. It defaults to 0.
      • newVersion {{optional_inline}}
        • : An unsigned long representing the new version of the database, or null if the database is being deleted. It defaults is null.

Return value

A new {{domxref("IDBVersionChangeEvent")}} object.

Examples

For a full working example, see our To-do Notifications app (view example live).

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}