Communication between HTML in WebBrowser and windows phone app

 ̄綄美尐妖づ 提交于 2019-12-11 11:37:34

问题


I have some static html files downloaded into Isolated store. I am trying to open those files using Web Browser control inside windows phone app. 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.

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. Will WinJS supports the same for Windows Phone 8?


回答1:


For receiving data from HTML to phone:

You need to add event handler for ScriptNotify event of WebBrowser. 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.

in javascript: window.external.Notify(args);

in 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:

You need to use InvokeScript() method of WebBrowser. There you need to pass name of the function in javascript and input parameters if any.

in javascript: function doSomething(args) { }

in CS: browser.InvokeScript("doSomething", args);

Hope it helps.



来源:https://stackoverflow.com/questions/25262029/communication-between-html-in-webbrowser-and-windows-phone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!