星期二, 11月 13, 2007

javascript call c# function

1.c#裡的function
public void test()
{
Messagebox.show(""Are you shit on me?");
}

2.加入com
在namespace後的第一行
比public class 更之前 加入 [System.Runtime.InteropServices.ComVisibleAttribute(true)]
ex.
namespace ezLa
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class ezLa : Form
...
}


2.為webBrowser加入指定物件
webBrowser1.ObjectForScripting = this; //寫在建構子

3.在html裡加入要觸發
ex.利用button實作
在onclick="window.external.test()" 就ok啦

沒有留言: