1)在c#中調用js函數
若是要傳值,則能夠定義object[]數組。
具體方法以下例子:
首先在js中定義被c#調用的方法:
function Messageaa(message)
{
alert(message);
}
在c#調用js方法Messageaa
private void button1_Click(object sender, EventArgs e)
{
// 調用JavaScript的messageBox方法,並傳入參數
object[] objects = new object[1];
objects[0] = "c# call javascript";
webBrowser1.Document.InvokeScript("Messageaa", objects);
}
2) 在js中調用c#方法
在js中調用c#方法則相對比較簡單:
namespace WindowsFormsApplication1
{
//申名託管類型,對com是可見的
[System.Runtime.InteropServices.ComVisible(true)]
}
private void Form1_Load(object sender, EventArgs e)
{javascript