由于visual studio2005 中WebBrowser控件已经实现了IDocHostUIHandler,所以
只要把应用程序属性类的 "com可见"选上.
再给 this.webBrowser1.ObjectForScripting = this; 赋值就行了
代码如下:
form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.webBrowser1.Navigate("F:\\WindowsApplication3\\3.html"); this.webBrowser1.ObjectForScripting = this; } private void Form1_Load(object sender, EventArgs e) { } public string test(string jsstr) { return "inapplication hello , "+jsstr; } } }
|
3.html
<html> <head> <script language=javascript> function go(){ alert(window.external.test(" call at 3.html js ")); } </script> <head> <body> <input type="button" onclick= "go();" value="test">
</body> </html>
|
阅读(6213) | 评论(1) | 转发(0) |