//navigator.online;
if (navigator.onLine) { alert('online'); } else { alert('offline'); }
window.addEventListener('offline', function onOffline() {
// We are offline
});
window.addEventListener('online', function onOnline() {
// We got the connection back
});
localStorage.myKey = myValue;
var myDB; var request = window.indexedDB.open("MyBookShop", 1); request.onsuccess = function onSuccess(event) { myDB = event.target.result; };
request.onerror = function onError(event) {
alert('Sorry, cannot open the DB');
};
// Once opened the connection
request.onupgradeneeded = function onUpgradedNeeded(event) { var db = event.target.result; var oldVersion = event.oldVersion; // Apply any schema upgrade if needed createSchema(db); };
function createSchema(db) { // { 'isbn' : <String> (primary key),
// 'title' : <String>, // 'date' : <Date>, // 'author' : <String>, // 'cover': <Blob> // } var objectStore = db.createObjectStore('books',
{ keyPath: 'isbn' });
// Search by title
objectStore.createIndex('title', 'title');
// Search by author
objectStore.createIndex('author', 'author'); }
var transaction = myDB.transaction(['books'], 'readwrite');
transaction.onerror = function() { // Handle error };
transaction.oncomplete = function() { // Handle success };
var objectStore = transaction.objectStore('books');
objectStore.add(book);
var objectStore = myDB.transaction('books').objectStore('books');
var index = objectStore.index('author'); index.openCursor().onsuccess = function(event) { var cursor = event.target.result; if (!cursor) {/* We finished */} // Process each object in cursor.value cursor.continue(); };
CACHE MANIFEST
# version 1.0
index.html
style.css
image.png
# Use from network if available
NETWORK:
*
# Fallback content
FALLBACK:
/ offline.html
<html manifest="manifest.appcache"> <h1>YAY!</h1>
</html>
{ "name": "My App", "description": "My elevator pitch goes here", "launch_path": "/",
"appcache_path": "manifest.appcache",
"icons": { "128": "/img/icon-128.png" }, "developer": { "name": "Your name or organization", "url": "http://your-homepage-here.org" }, "default_locale": "en" }
{ "name": "My App", "description": "My elevator pitch goes here", "launch_path": "/",
"package_path": "/application.zip",
"size": 1000000,
"icons": { "128": "/img/icon-128.png" }, "developer": { "name": "Your name or organization", "url": "http://your-homepage-here.org" }, "default_locale": "en" }