【问题标题】:Insert text from C# into webview - UWP将 C# 中的文本插入 webview - UWP
【发布时间】:2019-05-05 20:47:24
【问题描述】:

我目前正在开发一个使用 webview 来显示 webapp 的应用程序。我想让它让用户不必在每次启动应用程序时都输入他的用户名。我想用 c# 中的文本自动填充 webview 中的文本框。到目前为止,我有以下代码,但我认为我的 javascript 远非好(我对 javascript 没有任何具体知识)。

 private async void asyncjevoordeuser()
    {
        var inputValue = "test";

        var functionString = string.Format(@"document.getElementById('username');", inputValue);
        await WebView.InvokeScriptAsync("eval", new string[] { functionString });

    }

我正在调用这个方法

     private void WebView_LoadCompleted(object sender, NavigationEventArgs e)
  {
      asyncjevoordeuser();
    }

我希望有人可以帮助我。

【问题讨论】:

  • functionString 的值是多少?你检查了吗?
  • 文本框是否被填充?

标签: javascript c# webview uwp


【解决方案1】:
await WebViewObj.InvokeScriptAsync("eval", new string[] { "document.getElementById('username').value = 'username here';" }); 

【讨论】:

    猜你喜欢
    • 2018-08-21
    • 2018-10-05
    • 1970-01-01
    • 2016-11-25
    • 2016-11-03
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    相关资源
    最近更新 更多