<Html>
<Head>
<Title> </title>
<Script type = "text/javascript">
Function ShowMessage (message)
{
Alert (message );
}
Function ShowWinFormsMessage (){
Var msg = document. getElementById ('txtmessage'). value;
Return window. external. ShowMessage (msg );
}
</Script>
</Head>
<Body>
<Input type = "text" id = "txtMessage"/>
<Input type = "button" value = "Show Message" onclick = "ShowWinFormsMessage ()"/>
</Body>
</Html>
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace WebBrowserJavaScriptExample
{
Public partial class frmMain: Form
{
Public frmMain ()
{
InitializeComponent ();
WebBrowser1.ObjectForScripting = new ScriptManager (this );
}
Private void btnShowMessage_Click (object sender, EventArgs e)
{
Object [] o = new object [1];
O [0] = txtMessage. Text;
Object result = this. webBrowser1.Document. InvokeScript ("ShowMessage", o );
}
Private void frmMain_Load (object sender, EventArgs e)
{
This. webBrowser1.Navigate (@ "E: \ Projects \ 2010 \ webbrowser?criptexample \ webbrowser=criptexample \ TestPage.htm ");
}
[ComVisible (true)]
Public class ScriptManager
{
FrmMain _ form;
Public ScriptManager (frmMain form)
{
_ Form = form;
}
Public void ShowMessage (object obj)
{
MessageBox. Show (obj. ToString ());
}
}
}