【问题标题】:How do I modify an element within a Nativescript <Webview>如何修改 Nativescript <Webview> 中的元素
【发布时间】:2018-04-07 06:50:36
【问题描述】:

在我的 Nativescript Angular 2 Typescript 应用程序中,我想要一个 Nativescript WebView 加载包含 html 文本输入字段的任何(不受我控制的)远程网站。

然后我想用我的 NativeScript 应用程序具有的值填充这些输入字段。

我之前在android studio中使用java做过这个,你可以在其中运行一些JS并修改webview的dom。但是在不运行 android 特定的本机代码的情况下使用 Nativescript 是否可行?

编辑:我想做这样的事情Fill fields in webview automatically

【问题讨论】:

    标签: angular typescript nativescript angular2-nativescript


    【解决方案1】:

    如果你能添加nativescript-webview-interface.js,你就可以做到这一点 在您的远程 html 中。如果是这样,您可以按事件传达主要的 nativescript 页面和 webview 页面。

    在此处查看文档:https://github.com/shripalsoni04/nativescript-webview-interface

    这里有一个例子:https://github.com/shripalsoni04/nativescript-webview-interface-demo

    【讨论】:

    • 对不起,我应该指定这不是我的远程 html。这只是我想填写文本表单的任何页面。
    【解决方案2】:

    我最终只需要运行特定于 android 的代码,这就是它在我的组件中作为函数的样子

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2018-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多