0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

thanks for the suggestion but i have already used that example.. and that example only implements sending data from JS to C# code while i need reverse of it i.e. i need to send data from C# to JS.
I've added a little bit. Does that help?
const string JavaScriptFunction = "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}"; WKUserContentController userController; userController = new WKUserContentController(); this is my Renderer code.. can you little bit more elaborate where should i write your suggested code ??
I'm sorry, but it's impossible to give you concrete code. I have no idea on what you are doing exactly or what your requirements are. I think I have given you some good pointers, the rest is up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.