In the WebBrowser control, window.external is not available

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

+4
source share
3 answers

Your code seems correct, but the window.external.notify () method accepts a String parameter, not an Integer. Instead, try window.external.notify ('123'). Hope this helps.

0
source

I suspect your problem is that you did not provide a valid HTML5 document, since your (body and html) elements are not closed.

+1
source

Source: https://habr.com/ru/post/1383281/


All Articles