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); 
2
  • 2
    Is ObjectForScripting what you're looking far? stackoverflow.com/a/23441190/1768303 Commented Mar 19, 2015 at 7:52
  • 1
    ObjectForScripting worked perfectly. Thanks for the tip. Commented Mar 19, 2015 at 21:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.