0
votes

Within my Nativescript Angular 2 Typescript app, I want have a Nativescript WebView load any (not controlled by me) remote website that contains html text input fields.

Then I want to fill those input fields in with values that my NativeScript app has.

I've done this in android studio using java before, where you can run some JS and modify the dom of the webview. But is this possible with Nativescript without running android specific native code?

Edit: I want to do something like this Fill fields in webview automatically

2

2 Answers

1
votes

you can accomplish this if you are able to add nativescript-webview-interface.js in your remote html. If so you can just communicate the main nativescript page and the webview page by event.

look doc here: https://github.com/shripalsoni04/nativescript-webview-interface

an example here: https://github.com/shripalsoni04/nativescript-webview-interface-demo

0
votes

I ended up just having to run android specific code, and this is what it was as a function in my component

fillin(){
        let webview: WebView = this.webViewRef.nativeElement;        
        webview.android.getSettings().setDomStorageEnabled(true);
        webview.android.loadUrl("javascript:var myvar = document.getElementsByTagName('textarea')[0].value = 'poop';");        
    }