Chinaunix首页 | 论坛 | 博客
  • 博客访问: 470643
  • 博文数量: 66
  • 博客积分: 2125
  • 博客等级: 大尉
  • 技术积分: 704
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-08 13:42
个人简介

空气中的尘埃

文章分类

全部博文(66)

文章存档

2019年(1)

2017年(4)

2016年(2)

2015年(4)

2014年(4)

2013年(2)

2012年(5)

2011年(6)

2010年(9)

2009年(8)

2008年(12)

2007年(6)

2006年(2)

2005年(1)

我的朋友

分类: WINDOWS

2008-08-28 12:33:36

    由于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>

阅读(6064) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-09-09 13:26:53

vb6可能做到吗? benhaizi@gmail.com