简体   繁体   中英

Insert text from C# into webview - UWP

I am currently working on an app where i use a webview to display a webapp. I want to make it so that a user does not have to type his username everytime he starts the app . I want to automatically fill the textbox in the webview with text from c#. I have the following code untill now but I think my javascript is far from good (I don't have any specific knowledge about javascript).

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

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

    }

I am calling this method from

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

I hope someone can help me out.

await WebViewObj.InvokeScriptAsync("eval", new string[] { "document.getElementById('username').value = 'username here';" }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM