using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.IO.FileInfo file = new System.IO.FileInfo(Application.StartupPath+@"\test1.htm");
webBrowser1.Url = new Uri(file.FullName);
webBrowser1.ObjectForScripting = this;
}
private void button1_Click(object sender, EventArgs e)
{
object[] objects = new object[1];
objects[0]="C#访问javascript脚本";
webBrowser1.Document.InvokeScript("messageBox", objects);
}
public void MyMessageBox(string message)
{
MessageBox.Show(message);
}
}
}
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class WinOperationClass
{
public void MyMessageBox1()
{
MessageBox.Show(message);
}
public void ShowForm()
{
Form2 f2 = new Form2();
f2.WindowState = FormWindowState.Normal;
f2.Show();
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function messageBox(message)
{
alert(message);
}
</script>
</head>
<body>
<button onclick="window.external.MyMessageBox('javascript访问C#代码')">javascript访问C#代码</button>
<a href="javascript:window.external.MyMessageBox1()">javascript访问C#代码</a>
<a href="javascript:window.external.ShowForm()">javascript访问C#代码</a>
</body>
</html>
webBrowser1.ObjectForScripting = this;
webBrowser1.ObjectForScripting = this;
WinOperationClass w=new WinOperationClass(); webBrowser1.ObjectForScripting = w;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有