[英]Communication between HTML in WebBrowser and windows phone app
I have some static html files downloaded into Isolated store. 我有一些静态html文件下载到隔离存储中。 I am trying to open those files using Web Browser control inside windows phone app.
我正在尝试使用Windows Phone应用程序内的Web浏览器控件打开这些文件。 Now every HTML file will communicate with back-end code through javascript, and
window.external.notify()
is not able to apply for all html pages. 现在,每个HTML文件都将通过javascript与后端代码进行通信,并且
window.external.notify()
无法应用于所有html页面。
So my question is, 所以我的问题是
Is there any API like (in iOS) WebViewJavascriptBridge and GAJavaScript or like (android) Javascript Interface
available for windows phone 8 which will communicate with HTML in WebBrowser and windows phone app. 是否有适用于Windows Phone 8的API(例如,iOS中的WebViewJavascriptBridge和GAJavaScript或类似(android)
Javascript Interface
),这些API可以在WebBrowser和Windows Phone应用程序中与HTML进行通信。 Will WinJS supports the same for Windows Phone 8? WinJS是否支持Windows Phone 8的相同功能?
For receiving data from HTML to phone: 从HTML接收数据到电话:
You need to add event handler for ScriptNotify event of WebBrowser. 您需要为WebBrowser的ScriptNotify事件添加事件处理程序。 After that, whenever you call window.external.Notify(args) inside html page, ScriptNotify will fire and you'll get the args in Value property of NotifyEventArgs parameter.
之后,每当您在html页面中调用window.external.Notify(args)时,ScriptNotify都会触发,并且您将在NotifyEventArgs参数的Value属性中获取args。
in javascript: window.external.Notify(args);
在javascript中:
window.external.Notify(args);
in CS: 在CS中:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
browser.ScriptNotify += browser_ScriptNotify;
}
private void browser_ScriptNotify(object sender, NotifyEventArgs e)
{
var valueFromBrowser = e.Value;
}
For passing data from phone to HTML: 要将数据从手机传递到HTML:
You need to use InvokeScript() method of WebBrowser. 您需要使用WebBrowser的InvokeScript()方法。 There you need to pass name of the function in javascript and input parameters if any.
在那里,您需要在javascript中传递函数名称,并输入参数(如果有)。
in javascript: function doSomething(args) { }
在javascript中:
function doSomething(args) { }
in CS: browser.InvokeScript("doSomething", args);
在CS中:
browser.InvokeScript("doSomething", args);
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.