I would like to call C # methods in 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); }
123
is expected to appear in the debug window.
When the <button>Push</button>
is window.external.notify
, window.external.notify
never called. In fact, window.external
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
Links links: MSDN: window.external.notify
, Any way to set a WebBrowser WP7 control height Dynamically and scroll lock? and Display HTML Content in Windows Phone 7
source share