简体   繁体   中英

How to send data from C# to webview HTML file in Xamarin

I am developing a project using Xamarin.forms. I need to get data from webservice and then need to show that data on WebView HTML page. Suggest me any Xamarin.forms inbuild function or any renderer class to implement this feature.

To send data from C# page to HTML we need to call javascript function defined in that HTML file. We are having Eval function in Xamarin Forms.

WebViewObj.Eval(string.Format("JSFunctionName({0})", DataInStringFormat));

By using above function we can send the data to JavaScript function.

You probably want to look at the documentation for creating a HybridWebView .

This document describes how you can create your own kind of WebView which can handle JavaScript events for you. Although it may not be 100% accurate to what you want, it will give you an idea and you can pick it up from there.

As you noted in the comment you need to implement C# to JS. In the same custom renderers you can call functions for this on the WebViews. For iOS you can use InvokeJavaScript(); and for Android (mis)use LoadUrl("javascript: alert('Hi!');") .

For more info on this, follow this great post by Adam Pedley.

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