Communication Between Html In Webbrowser And Windows Phone App
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 communica
Solution 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:
protectedoverridevoidOnNavigatedTo(NavigationEventArgs e)
{
browser.ScriptNotify += browser_ScriptNotify;
}
privatevoidbrowser_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.
Post a Comment for "Communication Between Html In Webbrowser And Windows Phone App"