Reputation: 131
I'm working on my first universal app. It's a simple webview but I would like to "control" it with some native buttons. For example I have this html div:
<div id="country-change">
<i data-parameter="sessionCity" data-title="Scegli" class="fa fa-pencil change-location">Cambia</i>
</div>
Or
<a href="/me/tickets" data-animation="none" class="icon note">
I miei biglietti
I can't access the full code because the webpage that I'm loading in the webview is not mine (I just know that clicking this div I do something, the Javascript code behind that, at first sight, looks like spaghetti code for me), but what I'm trying to do is to simulate a click in the webview pressing a C#/XAML button. I tried with the following code, but it doesn't seem to work.
private async void AppBarButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
await view.InvokeScriptAsync("eval", new String[] { "window.location = document.getElementsByClassName('icon note').href" });
}
Could you help me? Is it possible to simulate a click in the webview with some magic C# code? :)
Upvotes: 0
Views: 841
Reputation: 689
I suggest you do some search before asking a question. Anyway, Here's the possible solution.
await view.InvokeScriptAsync("eval",new String[] {"document.getElementById("your control's id").click();"});
Upvotes: 1