WinForm与Javascript交互
来源:互联网 发布:网络视频直播方案 编辑:程序博客网 时间:2024/05/23 12:15
一、HTMLPage1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Page</title>
<script type="text/javascript" language="javascript">
function ShopXG(obj)
{
alert(obj);
}
function InvokeFunc()
{
window.external.ShowMessage("呵呵");
}
</script>
</head>
<body>
<input type="button" id="aa" value="测试" onclick="InvokeFunc();"/>
</body>
</html>
二、创建一个WinForm应用程序,在应用程序窗体上添加一个浏览器控件:webBrowser1
添加一个button按钮。Button1用来测试调用JS事件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
namespace WindowsFormsApplication1
{
//要想调用JS的类都需要添加一下两句
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.webBrowser1.Url = new Uri(Application.StartupPath + @"\HTMLPage1.htm");
webBrowser1.ObjectForScripting = this; //这句是必不可少的,是调用JS的前提
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("ShopXG",new object[]{"这是WinForm调用JS的一个测试!"});
}
public void ShowMessage(string message)
{
MessageBox.Show("这是JS调用的WinFormc程序的一个测试!");
}
}
}
- WinForm与Javascript交互
- WinForm与Javascript交互
- WinForm与Javascript交互
- c# webbrowser与winform交互访问,javascript参数调用控制程序
- [Winform]js与webbrowser交互
- [AJAA]Asynchronization JavaScript And ActiveX WinForm与Flash交互 思想参考3
- [AJAA]Asynchronization JavaScript And ActiveX WinForm与flash.ocx交互 思想参考4
- [AJAA]Asynchronization JavaScript And ActiveX WinForm与Flash异步交互 思想参考6
- WebBroWebBrowser控件上的代码(Javascript、Html Dom)与Winform控件本身的交互
- winform与javascript
- applet与javascript交互
- applet与javascript交互
- javascript与xml交互
- Silverlight与JavaScript交互
- Flex与JavaScript交互
- PHP与JavaScript交互
- ATL与JavaScript交互
- C#与JavaScript交互
- CHAPTER 1 A Simple Web Server
- 线程之Timer
- 关于判断真假币重量的问题
- kprobe实现轻量级内核热补丁机制
- VC++中的MFC程序的执行过程
- WinForm与Javascript交互
- Main Responsibilities:
- 2011-9-17 17:59:04
- 野指针(转载)
- C语言循环的小艺术
- sfs
- js日历多选(在表单中显示)
- 对scanf函数的认识
- linux中profile与bashrc的区别