WebView, how can i implement a button and get response on button click.

GayawarGayawar INMember ✭✭
edited June 2017 in Xamarin.Forms

Hi,
I have implement a page so that it can handle the HTML tag, as the page is dynamic so i used the Xamarin.Forms.WebView() to display the page content, but the page also has a button and i need to do some operation on button's click.

I am not sure whether i am moving in right direction.

If i am in right direction kindly help me with the way i can implement the button to handle click event.

Thanks in Advance

Answers

  • JohnHardmanJohnHardman GBUniversity mod
    edited June 2017

    @Gayawar - The button is part of the HTML in the WebView? If so, what do you want to happen when it is pressed - execute script (e.g. JavaScript) in the WebView, or execute C# in your Xamarin.Forms code?

    If you want to call C# from your WebView, see

    https://forums.xamarin.com/discussion/72681/what-is-the-easiest-way-to-call-c-method-from-javascript-in-webview

    and

    https://xamarinhelp.com/xamarin-forms-webview-executing-javascript/

  • y_SBSICy_SBSIC USMember ✭✭✭

    @JohnHardman @Gayawar Hi ,
    I have used a webview for displaying HTML content in description field, I have a text in description "go to Home" and on click of that text I want to navigate to another page but i am not able to detect that click on view Model or on code behind.

  • JohnHardmanJohnHardman GBUniversity mod

    @y_SBSIC said:
    @JohnHardman @Gayawar Hi ,
    I have used a webview for displaying HTML content in description field, I have a text in description "go to Home" and on click of that text I want to navigate to another page but i am not able to detect that click on view Model or on code behind.

    The first step is to get some JavaScript executed when the text is clicked. Do that first, with the JavaScript (temporarily) providing visual feedback within the WebView.

    Once you've got the JavaScript executing, make use of the links posted above to change the JavaScript to call back into your C# code.

    Alternatively, you could have the JavaScript navigate to another HTML page, but have a Navigating event handler on your WebView, so that when the event handler is triggered, your C# navigates to your home page.

Sign In or Register to comment.