码迷,mamicode.com
首页 > 编程语言 > 详细

html,JavaScript调用winfrom方法

时间:2015-11-24 22:54:28      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

---恢复内容开始---

目的:
  在动画上面添加点击事件,通过JavaScript调用winfrom方法

1、创建一个页面 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
using System.Runtime.InteropServices;

namespace Demo
{
   //设置可以调用的范围 [PermissionSet(SecurityAction.Demand, Name
= "FullTrust")] [ComVisible(true)] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { } public void ShowMsg(string msg) { MessageBox.Show(msg); } private void button1_Click(object sender, EventArgs e) { webBrowser2.Document.InvokeScript("Run", new object[] { "CShareFunction" }); } private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { string flashUri = "D:/text.html"; this.webBrowser2.Url = new Uri(flashUri); webBrowser2.ObjectForScripting = this;//具体公开的对象,这里可以公开自定义对象 } } }

2、html页面

<html>
 <head> 
  <meta charset="utf-8" /> 
 </head> 
 <body > 
  <img src="BankPay.gif"  style="position: absolute; width:100%; top:0px; left:0px; right:0px; bottom:0px; height:100%; z-index:100;"  /> 
  <div style="position: absolute; width:100%; top:0px; left:0px; right:0px; bottom:0px; height:100%; z-index:101;" onclick="Run(‘浏览器打开‘)">11111 </div>  
  <script type="text/javascript" charset="utf-8">
    function Run(str){
        window.external.ShowMsg(str);
    }
   </script> 
 </body>
</html>

3、注意事项:如果采用flash的话,页面是不能获取到点击事件的

4、flash 的解决方法,通过转换为Gif动画的图片来解决

---恢复内容结束---

html,JavaScript调用winfrom方法

标签:

原文地址:http://www.cnblogs.com/cbread/p/4993151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!