0

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

Eric Nelson
  • 337
  • 4
  • 15

2 Answers2

1

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

Fetrarij
  • 7,176
  • 3
  • 27
  • 35
  • Sorry, I should have specified that this is not my remote html. This is just any page that I want to fill in a text form. – Eric Nelson Oct 26 '17 at 18:33
0

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';");        
    }
Eric Nelson
  • 337
  • 4
  • 15