I have a WPF application that uses the WPF WebBrowser control to display interesting web pages to our developers on a flatscreen display (like a news feed).
The tro
you can use this trick
vb.net
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_CLOSE As Short = &H10s
and call last lib :
dim hwnd
dim vreturnvalue
hwnd = FindWindow(vbNullString,"script error")
if hwnd<>0 then vreturnvalue = SendMessage(hwnd, WM_CLOSE, &O0s, &O0s)
I've also found an interesting way to disable JavaScript errors. But you need to use at least .Net Framework 4.0 because of using elegant dynamic type.
You need to subscribe to the LoadCompleted event of the WebBrowser element:
<WebBrowser x:Name="Browser"
LoadCompleted="Browser_OnLoadCompleted" />
After that you need to write an event handler that looks like below:
void Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
{
var browser = sender as WebBrowser;
if (browser == null || browser.Document == null)
return;
dynamic document = browser.Document;
if (document.readyState != "complete")
return;
dynamic script = document.createElement("script");
script.type = @"text/javascript";
script.text = @"window.onerror = function(msg,url,line){return true;}";
document.head.appendChild(script);
}