I'd like to call C# methods within a WebBrowser Control. Below is my code:
In XAML,
<phone:WebBrowser Margin="0,0,0,0" Name="WebBrowserForDetails" VerticalAlignment="Top" Height="300" ScriptNotify="WebBrowserForDetails_ScriptNotify" IsScriptEnabled="True" />
In C#,
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string html = string.Format("<html><head><title></title><script type=\"text/javascript\">{0}</script></head><body><button onclick=\"call();\">Push</button>", "function call(){ window.external.notify(123) ;}");
WebBrowserForDetails.NavigateToString(html);
}
private void WebBrowserForDetails_ScriptNotify(Object sender, NotifyEventArgs e)
{
Debug.WriteLine(e.Value);
}
Expected to see 123
in the debug window.
When the <button>Push</button>
is pushed, window.external.notify
is never called. In fact, window.external
is not available. I would like to call the window.external.notify
function from the WebBrowser control to call the WebBrowserForDetails_ScriptNotify
method. What should I do?
Edit
Reference links: MSDN: window.external.notify
, Any way to set the WP7 Webbrowser control height Dynamically and lock scrolling? and Displaying HTML Content in Windows Phone 7