[ad_1]
I wanna use NativeScript’s WebView to preprocess a few of my knowledge (it makes use of XHTML so i need to use WebView and it is evaluateJavascript methodology).
However for the preprocess i do not wish to render the entire WebView only for a blink of an eye fixed time, so i created a service wich creates a new WebView() occasion. Now i can set the src attribute this manner and all others, like top and with, but when i wish to name the evaluateJavascript operate I can not. Code under.
take a look at() {
//create new webview occasion
this.wv = new WebView();
//all of this works
this.wv.set('top', 100);
this.wv.setProperty('width', 200);
this.wv.setProperty('src', 'some url right here');
//this doesn't work
this.wv.android.evaluateJavascript(
'operate take a look at(){ return 1;} take a look at();',
new android.webkit.ValueCallback({
onReceiveValue: operate (res: any) {
console.log(res);
}
})
);
}
The set and setProperty strategies are fantastic, however the evaluateJavascript sais it may’t be referred to as on undefiend.
console.log(this.wv.android); //undefined
Additionally the WebView loaded occasion doesn’t run, if have one thing like this within the take a look at operate above.
this.wv.on('loadFinished', (knowledge) => {
console.log('loadFinished');
console.dir(knowledge);
});
Then again, if i create a part, put a WebView component in it, than pay attention for the loadFinished occasion, than i can run the JS seen above, like this:
webViewLoaded(webargs) {
// console.log('WEBVIEW LOADED');
this.webView = webargs.object;
this.webVie.android.evaluateJavascript(
'operate take a look at(){ return 1;} take a look at();',
new android.webkit.ValueCallback({
onReceiveValue: operate (res: any) {
console.log(res);
}
})
);
}
//It run correctly.
}
So my questions are:
Am i proper and the loadFinished occasion doesn’t run on the creation of latest WebView() occasion? If it does run, how am i able to add a listener to it?
Whats the distinction between the instace of latest WebView() and the thing returned within the args param above? And why this.wv.android is undefined within the take a look at fuction above?
Am i able to run evaluateJavascript on a WebView occasion that doesn’t have any HTML counterpart and isn’t even rendered out? If sure, how?
Am i obligated to render the WebView to make use of it propery?
[ad_2]
