Reputation: 277
I'm using webwiew-ext and I want to launch events from webview-ext form to taking data and save it using nativescript script sqlite This is the example I have done to test the events but it doesn't work : my js file :
function callFromNativeScript() {
window.nsWebViewBridgee.emit("got", { huba: "hop" });
console.log("got a message from nativescript");
}
Loaded in the html file like that in the header:
<script src="../js/index.js" type="text/javascript"></script>
my nativescript main.js file :
const Sqlite=require("nativescript-sqlite");
exports.pageLoaded =function(args ){
page = args.object;
var db_promise = new Sqlite("test.db", function(err,db) {
if (err) {
console.error("We failed to open database", err);
} else {
console.log("Is a Sqlite Database:", Sqlite.isSqlite(db) ? "Yes" : "No");
db.get('select * from test where id=1 ', [1], function(err, row) {
if(row){
console.log("Row of data was: ", row);
}else if(err)
{
console.log("les guignols");
} // Prints [["Field1", "Field2",...]]
});
// This should ALWAYS be true, db object is open in the "Callback" if no errors occurred
console.log("Are we open yet (Inside Callback)? ", db.isOpen() ? "Yes" : "No"); // Yes
}
});
window.nsWebViewBridge.on("got",function(message){
console.log("Salut"+message);
console.log("hello");
});
console.log("bonjour");
}
My xml file file :
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" actionBarHidden="true" xmlns:nota="@nota/nativescript-webview-ext">
<nota:WebViewExt src="~/html/index.html"> </nota:WebViewExt> </Page>
Upvotes: 0
Views: 541
Reputation: 1078
I am using another webview module
which has built in functions to execute code within the webview.
Upvotes: 1