I try to send some text into a webView control from xamarin.forms. There are plenty of solution, which I almost all tried... ;-)
So actually they work great, but I have always to click a button on the html file, which I load into this webView, that I can pass some text into the html file. But I would like to pass the text without clicking on this button. The Text should be there, when the webView has loaded.
Here some code:
In the xaml.cs I load the WebView:
protected override void OnAppearing()
{
base.OnAppearing();
webViewElement.Source = new HtmlWebViewSource();
webViewElement.Source = DependencyService.Get<IBaseUrl>().Get();
webViewElement.RegisterAction(ExecuteActionFromJavascript);
ExecuteSetFromJavascript();
}
then with ExecuteSetFromJavascript() i call a function which is in the html file:
private async void ExecuteSetFromJavascript()
{
var result = "Hello";
if (result != null)
{
var test = await webViewElement.EvaluateJavaScriptAsync($"updatetextonwebview('{result}')");
}
}
this is the function in the html file:
function updatetextonwebview(text) {
alert(text);
// document.getElementById("content").innerHTML = text;
}
So now the page should Alert "Hello" when the updatetextonwebview is called.
but that doesn't make it. Maybe the html page is not ready when i call this funciton!
Does anyone have an idea how I can get to my solution?
Thanks in advance...