html、JavaScriptはwifromのメソッドを呼び出します.

4135 ワード

---復旧内容の開始---
目的:動画にクリックイベントを追加し、JavaScriptを通じてWindowsを呼び出す方法
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動画の画像に変換して解決します.
---復旧内容の終了---