javascript - Error processing SQL: TypeError: window.openDatabase is not a function -
i have strange issue in code. have create simple db_function.js
manage js function inside html page.
i calling function inside <body onload="call_db()">
first initialize db , create table if needed.
issue here ,
- working : chrome
- not working : android mobile & fire fox
code below :
db_function.js
function call_db() { try { alert("call_db"); var db = window.opendatabase("database", "1.0", "cordova demo", 200000); db.transaction(populatedb, errorcb, successcb); } catch (err) { alert("error processing sql: " + err); } } function populatedb(tx) { try { alert("call_table"); tx.executesql('drop table if exists demo'); tx.executesql('create table if not exists demo (id unique, data)'); tx.executesql('insert demo (id, data) values (3, "c")'); tx.executesql('insert demo (id, data) values (4, "k")'); } catch (err) { alert("error processing sql: " + err); } } function errorcb(tx, err) { alert("error processing sql: " + err); } // transaction success callback function successcb() { alert("success!"); }
test.html
<!doctype html> <html> <head> <title>storage example</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8" src="js/db_function.js"></script> </head> <body onload="call_db()"> <h1>example</h1> <p>database</p> </body> </html>
here js fiddle please me don't know wrong.
thanks read query.
you using web sql database, not supported firefox. also, specification abandoned w3c.
have @ indexeddb (caniuse) instead. there @ least 1 shim make indexeddb work in browsers support web sql database.
the code "works" in this updated fiddle on android browser 4.1.2
.
Comments
Post a Comment