Using requests to open a database in IE 10

22Dec11

Because the Indexed Database API specification is still evolving, Windows Internet Explorer 10 and Metro style apps using JavaScript use a vendor prefix (“ms”) for the msIndexedDB property. For best results, use feature detection to access the IndexedDB API, as shown in the following example:

var ixDB;
if ( window.indexedDB ) {
ixDB = window.indexedDB;
}

else if ( window.msIndexedDB ) {
ixDB = window.msIndexedDB;

Opening a database

When you open a database, an IDBRequest object is returned; however, the request has not yet been processed. The object is used to track the results of the request, which will be known after the requested has been processed in the background. Use this object to define event handlers that react to the results of the request, as shown in the following example:

var dbReq = ixDB.open( “Database1” );
dbReq.onsuccess = function( evt ) {
oDB = evt.target.result;
};

Request objects support events such as onsuccess and onerror. In the previous example, an inline function assigns the results of the request to a global variable that maintains the connection to the opened database. The result varies according to the request.

Request objects execute when they go out of scope; that is, when the current JavaScript block finishes.

Advertisements


No Responses Yet to “Using requests to open a database in IE 10”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: