xamarin.forms Handle Clicked event on WebView

后端 未结 5 2248
陌清茗
陌清茗 2020-12-06 12:39

I want to handle the click/tap event on a WebView control

I\'ve tried the GestureRecognizers but nothing happens, i think maybe the WebView has some sort of making t

5条回答
  •  醉梦人生
    2020-12-06 13:07

    Another option is to handle the click in html and do a navigation that doesn't go anywhere. You can put something like this in your html

    ...

    So a click anywhere inside there would cause a navigation. If you only have a button, you could just use

    ...
    

    Then in your WebView control wire up the Navigating event, and check if the new url contains "#click". If so, do your click handling code and call e.Cancel=true in the event to prevent the browser from completing the navigation.

    Note that onclick handlers don't work on body or document elements in Xamarin Webview. At least not on iOS.

提交回复
热议问题