(Sometimes these are called 'installable web apps'.)
Installed apps might not be online and this is the first thing Apple tests in the app store review proccess.
We quickly realized we needed network introspection and persistence apis.
var states = {}
states[navigator.connection.UNKNOWN] = 'Unknown connection'
states[navigator.connection.ETHERNET] = 'Ethernet connection'
states[navigator.connection.WIFI] = 'WiFi connection'
states[navigator.connection.CELL_2G] = 'Cell 2G connection'
states[navigator.connection.CELL_3G] = 'Cell 3G connection'
states[navigator.connection.CELL_4G] = 'Cell 4G connection'
states[navigator.connection.NONE] = 'No network connection'
console.log(states[navigator.connection.type])
navigator.connection.addEventListener('change', function() {
console.log(navigator.connection.bandwidth);
}, false)
Lets check the spec!
// ever played with Infinity?
// one last wtf
console.log(navigator.onLine)
the whatwg spec
db.open('database-test');
db.execute('create table if not exists Test (Phrase text, Timestamp int)');
db.execute('insert into Test values (?, ?)', ['Monkey!', new Date().getTime()]);
var rs = db.execute('select * from Test order by Timestamp desc');
while (rs.isValidRow()) {
alert(rs.field(0) + '@' + rs.field(1));
rs.next();
}
rs.close();
(On 5.0 Browser. We no longer support.)
(On 5.0 Browser. We no longer support.)
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024)
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)')
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "whatevs")')
tx.executeSql('SELECT * FROM foo', [], printer)
})
function printer (tx, results) {
for (var i = 0, l = results.rows.length; i < l; i++) {
console.log(results.rows.item(i).text);
}
}
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024)
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)')
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "whatevs")')
tx.executeSql('SELECT * FROM fo', [], printer)
})
function printer (tx, results) {
for (var i = 0, l = results.rows.length; i < l; i++) {
console.log(results.rows.item(i).text);
}
}
Thusly renamed to Indexed DB.
var request = indexedDB.open('all-your-base')
request.onsuccess = function (e) {
var version = '1.0'
var db = e.target.result
if (version != db.version) {
// the only place you can create a store...deprecated for onupgradeneeded
var setVrequest = db.setVersion(version)
setVrequest.onsuccess = function(e) {
var store = db.createObjectStore('all-your-base', {keyPath: 'timeStamp'})
e.target.transaction.oncomplete = function() { console.log('created a store')}
}
}
}
var trans = db.transaction(['all-your-base'], 'readwrite')
var store = trans.objectStore('all-your-base')
var request = store.put({'text':'ya data store', 'timeStamp':new Date().getTime()})
request.onsuccess = request.onerror = function(e) { console.log(e) }
var cursorRequest = store.openCursor(IDBKeyRange.lowerBound(0))
cursorRequest.onsuccess = function(e) {
var result = e.target.result.value
result.continue()
}
// removing data is intuitive...
var request = store.delete(id)
So, can we use?
// store unlimited data on all browsers, accessible from any domain, I shit you not
window.name
// store unlimited data on all browsers, accessible from any domain, I shit you not
window.name
Use a spacebar or arrow keys to navigate