0

Can a Webbrowser control communicate with the C# class that created it? Is there anyway to set up something like ExternalInterface that works in Flash? I'm trying to get the following code to write to the console in C# or call a method in C#.

 HtmlElement button = webBrowser1.Document.CreateElement("div");
 button.InnerHtml = @"<INPUT TYPE='Text'><P><INPUT TYPE='Submit' Value='Submit' onclick='console.log('Clicked');'>";  
 webBrowser1.Document.GetElementById("myID").AppendChild(button);
user2146441
  • 220
  • 1
  • 19
  • 43

1 Answers1

1

A pretty hacky way would be to communicate via current location.. Button click:

onclick="window.location.href='#clicked';"

Then handle webBrowser1_Navigated and check the Url property. Split out the message after the # and log it to the console or call the method.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272