1 <html>
2
3 <head>
4
5     <meta http-equiv="Content-Language" content="zh-cn">
6
7     <script language="javascript" type="text/javascript">
8
9 <!-- ????C#??????????? -->
10
11 function messageBox(message)
12
13 {
14
15     alert(message);
16
17 }
18
19 </script>
20
21 </head>
22
23 <body>
24
25     <!-- ????C#???? -->
26
27     <button onclick="window.external.MyMessageBox('javascript????C#????')">
28
29         javascript????C#????</button>
30
31 </body>
32
33 </html><html>
34
35 <head>
36
37     <meta http-equiv="Content-Language" content="zh-cn">
38
39     <script language="javascript" type="text/javascript">
40
41 <!-- ????C#??????????? -->
42
43 function messageBox(message)
44
45 {
46
47     alert(message);
48
49 }
50
51     </script>
52
53 </head>
54
55 <body>
56
57     <!-- ????C#???? -->
58
59     <button onclick="window.external.MyMessageBox('javascript????C#????')">
60
61         javascript????C#????</button>
62
63 </body>
64
65 </html>
????????????Windows??ó???
????1.????Windows??ó??????
????2.??Form1?????????WebBrowser???
????3.??Form1?????????
????[System.Runtime.InteropServices.ComVisibleAttribute(true)]
?????????????????????com??????????????и?????????????
????[System.Runtime.InteropServices.ComVisibleAttribute(true)]
????public partial class Form1 : Form
????Url?????WebBrowser???????????·??
????ObjectForScripting??????????????????WebBrowser????е??????????????????????
??????Url???????????????в????????URL·????
????JavaScript???window.external????C#???????????????ObjectForScripting?????????????????????????????????????????????????£?
????System.IO.FileInfo file = new System.IO.FileInfo("index.htm");
????// WebBrowser???????????·??
????webBrowser1.Url = new Uri(file.FullName);
????// ??????????????????????
????webBrowser1.ObjectForScripting = this;
????4??C#????JavaScript????
???????WebBrowser???Document?????е?InvokeScript???????????????Javascript???????磺
????// ????JavaScript??messageBox????????????????
????object[] objects = new object[1];
????objects[0] = "C#????JavaScript???";
????webBrowser1.Document.InvokeScript("messageBox"?? objects);