Langsung ke konten utama

Postingan

Menampilkan postingan dengan label javascript

Delete indexeddb data by index

var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" };; var db; var transaction, objectStore; var request = indexedDB.open("IndexedDBname", 1);         request.onsuccess = function (evt) {        db = request.result;  var deleteindex = db.transaction(["indexdbtable"], "readwrite") .objectStore("indexdbtable")                 .delete(1); // example if you want to delete index no 1 deleteindex.onsuccess = function(event) { console.log("index 1 deleted" + "indexdbtable");  // log };  };

IndexedDB Fuzzy Search

This is how to create  key range between the search term and the search term with a 'z' letter at the final. db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important part, thank Velmont to point out 'prev' ) . onsuccess = function ( e ) { e || ( e = event ); var cursor = e . target . result ; if ( cursor ) { // console.log(cursor.value.column1 + ' = ' + cursor.value.column2); cursor . continue (); } }; If you need to order the result, so I defined a array before the transaction, then we call it when we loaded all data, like this: var result = []; db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important ...

Use HTML5 IndexedDB cursors to update existing records

The  HTML5   IndexedDB  is still in the working draft stage and not fully implemented in major Internet browsers yet. Nevertheless, I tried to use its asynchronous API to develop a  Google Maps  application. It took me a little while to figure out how to update an existing record in the IndexedDB  database store. This can be done by opening a read-write cursor to the record to be updated. Then call the cursor  update  method to replace it with the new record. An example Javascript code snippet is shown below. try { var objDb; //the database to update var store = 'myStore' ; //the database store to update var key = 88; //the key of the existing record to update var newRec = 'hello world' ; //the new record var objStore = null ; var objTrans = null ; var objCursor = null ; var objKeyRange = null ;   //...etc...open the database....etc... //open a read-write transaction objTrans = objDb.transaction(store,...

Image change with refresh or load a page by javascript

<SCRIPT LANGUAGE= "JavaScript" > var theImages = new Array()          theImages[0] = 'iphone-FASTEST.jpg'        theImages[1] = 'apple-3gs-0.jpg'        theImages[2] = 'apple-iphone-3gs-2-0.JPG'        theImages[3] = 'iphone-accessibility.jpg'        theImages[4] = 'iphone-cutcopypaste.jpg'                     var j = 0 var p = theImages.length; var preBuffer = new Array()   for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1));   function showImage(){ if (whichImage==0){ document.write( '<a href ="link.html"><img src="' +theImages[whichImage]+ '" border=0 width=452 height=181></a>'...