【问题标题】:Communication between Webbrowser control and C#Webbrowser控件与C#之间的通信
【发布时间】:2015-05-22 02:27:24
【问题描述】:

Webbrowser 控件可以与创建它的 C# 类通信吗?有没有办法设置像在 Flash 中工作的 ExternalInterface 之类的东西?我正在尝试将以下代码写入 C# 中的控制台或调用 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);

【问题讨论】:

标签: c# console webbrowser-control


【解决方案1】:

一种非常老套的方式是通过当前位置进行通信。按钮点击:

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

然后处理webBrowser1_Navigated 并检查Url 属性。将#后面的消息拆分出来,记录到控制台或者调用方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多