[ComVisible(true)]//这句话很重要,否则无法接收提示数据数据
public partial class Wzpolicy : Form
private void Wzpolicy_Load(object sender, EventArgs e)
{
wb.ObjectForScripting = this;//此属性是得到alert关键设置,否则可以禁止弹出,但是无法得到信息
wb.ScriptErrorsSuppressed = false;//禁用js错误提示
}
StringBuilder strAlertBuilder = new StringBuilder();
//禁用alert 信息 信息发送到alertMessage
strAlertBuilder.Append(" var _alert=window.alert;\n");strAlertBuilder.Append(" window.alert=function(s){\n");
strAlertBuilder.Append(" window.external.alertMessage(s);}\n");
//禁用confirm 信息, confirm 返回true。 信息发送到alertMessage
strAlertBuilder.Append(" var _confirm=window.confirm;\n");
strAlertBuilder.Append(" window.confirm=function(s){\n");
strAlertBuilder.Append(" window.external.alertMessage(s); return true;}\n");
//把js增加到页面
HtmlElement he = wb.Document.CreateElement("script");he.SetAttribute("type","text/javascript");
he.SetAttribute("text", strAlertBuilder.ToString());
wb.Document.Body.AppendChild(he);//add element
//接收提示 信息的方法
public void alertMessage(string s)
{
textBox1.Text += s+"\r\n";
}