I am new in windows and I want to handle a button that is into a WebView, when press button there is a js function to execute, and I need returned params in my C# class. In Android that is very easy, something like:
in WebView is loaded this code:
function sayHello(myParam) {
BindJsInAndroid.sayHello(myParam);
}
<input type="button" value="My Button" onClick="sayHello('Hello world')" /><br/>
and in android code:
WebView webView = (WebView) findViewById(R.id.web_view);
MyJavaScriptInterface myJavaScriptInterface = new MyJavaScriptInterface(mActivityContext);
webView.addJavascriptInterface(myJavaScriptInterface, "BindJsInAndroid");
//into MyJavaScriptInterface class
@JavascriptInterface
public void sayHello(String myParam) {
//here I get myParam
}
Is there a way to do that in UWP?
EDIT
I tried as is mentioned on msdn docs but can't get it work:
so my html src is:
<html>
<head>
<script type="text/javascript">
function js_function() {
bind_object.js_fun();
}
</script>
</head>
<body>
<div>
<input type="button" value="Button" onClick="js_function()" />
</div>
</body>
</html>
and I have in my C# code:
public MainPage() {
InitializeComponent();
//load html src
webView.NavigateToString(mas);
//bind js with C#
webView.AddWebAllowedObject("bind_object", new MyNativeClass());
}
[Windows.Foundation.Metadata.AllowForWeb]
public sealed class MyNativeClass {
public void js_fun() {
Debug.WriteLine("get js function call");
}
}
When I press button in webview I don't ge called js_fun() from C#...