navigator.onLine
Posted
by cf_PhillipSenn
on Stack Overflow
See other posts from Stack Overflow
or by cf_PhillipSenn
Published on 2010-02-24T18:43:09Z
Indexed on
2010/03/08
0:01 UTC
Read the original article
Hit count: 331
JavaScript
|html5
I'm playing with the incomplete example found at http://www.w3.org/TR/offline-webapps/
But I'm distressed to see comments in it like:
"renders the note somewhere", and
"report error", and
"// …"
So, will someone please help me write a valid example? Here's what I've got so far:
<!DOCTYPE HTML>
<html manifest="cache-manifest">
<head>
<script>
var db = openDatabase("notes", "", "The Example Notes App!", 1048576);
function renderNote(row) {
// renders the note somewhere
}
function reportError(source, message) {
// report error
}
function renderNotes() {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(title TEXT, body TEXT)',
[]);
tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
for(var i = 0; i < rs.rows.length; i++) {
renderNote(rs.rows[i]);
}
});
});
}
function insertNote(title, text) {
db.transaction(function(tx) {
tx.executeSql('INSERT INTO Notes VALUES(?, ?)', [ title, text ],
function(tx, rs) {
// …
},
function(tx, error) {
reportError('sql', error.message);
});
});
}
</script>
<style>
label {
display:block;
}
</style>
</head>
<body>
<form>
<label for="mytitle">Title:</label>
<input name="mytitle">
<label for="mytext">Text:</label>
<textarea name="mytext"></textarea>
<!-- There is no submit button because I want to save the info on every keystroke -->
</form>
</body>
</html>
I also know that I have to incorporate this in there somewhere:
if (navigator.onLine) {
// Send data using XMLHttpRequest
} else {
// Queue data locally to send later
}
But I'm not sure what even I would tie that too.
© Stack Overflow or respective owner