简体   繁体   English

WebBrowser中的HTML与Windows Phone应用之间的通信

[英]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中的WebViewJavascriptBridgeGAJavaScript或类似(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.

相关问题 Windows Phone 8中的应用到应用通信 - App to app communication in windows phone 8 Windows Phone7中Background(定期任务)与前景应用之间的通信? - Communication between Background(periodic task) and foreground app in windows phone7? 如何在Windows Phone 8 App中调整Web浏览器的大小 - How do resize a Webbrowser in Windows Phone 8 App Windows Phone 8 Web浏览器(缩放) - Windows Phone 8 Webbrowser (zoom) windows 应用程序和 UWP 应用程序之间的通信通道 - Communication channel between a windows app and UWP app 如何从Windows Phone Webbrowser控件隐藏html元素 - how to hide html elements from windows phone webbrowser control 我可以从Windows Phone 8在WebBrowser中加载动态HTML数据吗? - Can I load dynamic HTML data in a WebBrowser from Windows Phone 8? 如何在Windows Phone 8.0应用程序的WebBrowser中自动单击html按钮? - How to auto click a html button in WebBrowser of Windows phone 8.0 application? Windows手机应用,WebBrowser,iframe和谷歌地图不能一起使用 - Windows phone app, WebBrowser, iframe and google maps not working together 应用程序栏在Windows Phone App中向上滚动Webbrowser视图 - Application Bar scrolls up the Webbrowser view in Windows phone App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM