惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
AWS News Blog
AWS News Blog
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
美团技术团队
T
Threatpost
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
C
Cybersecurity and Infrastructure Security Agency CISA
F
Full Disclosure
博客园_首页
N
Netflix TechBlog - Medium
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Announcements
Recent Announcements
博客园 - Franky
P
Palo Alto Networks Blog
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
GbyAI
GbyAI

博客园 - rangeliu

批判下微软的sql面试题 SQL Server 报表系统导出txt格式方法 Reporting Service报表纵向单元格合并 SSAS中命名集(SET)的使用 返回指定成员所有下级成员的MDX语句 MDX学习——初始MDX [收藏]Oracle 性能优化 [收藏]使用XML技術實現OWC對數據庫的展示 十六進制的字符串轉換為double類型 [收藏]递归算出两个数字之间所有数字之和 [收藏]String与string的区别 [收藏]about协议的妙用 [收藏]中英文颜色对照表 [收藏]在C#程序中使用系统热键 [转载]动态调用WebService(C#) [转载] .NET脏字过滤算法 [转载]使用Response.Filter过滤非法词汇 [转载]asp.net面试集合 [转载]WEB开发碰到的问题及经验十八则
[收藏]C# WinForm程序如何与JS交互
rangeliu · 2009-01-24 · via 博客园 - rangeliu

  在使用C#开发winform程序过程中,我们经常会碰到嵌入了一个WebBrowser的浏览器控件。很多时候,我们需要在程序里控制网页的显示方式,或者调用网页当中的某个JS函数,反过来,也有可能网页也需要调用程序当中的函数来实现某些功能。下面我给大家讲解下如何互相进行交互。 

程序调用JS脚本如下: 
JS脚本代码:

<script type="text/javascript">  
function ShopXG(infor)   
{   
    alert(
'我要开网店、携购独立网店系统,模板最全,最专业的系统!');   
    
return;   
}   
</script>


C#代码调用如下:
注意: 类定义前需要加上下面两行,否则调用失败!

using System.Security.Permissions;   
  
[PermissionSet(SecurityAction.Demand, Name 
= "FullTrust")]   
[System.Runtime.InteropServices.ComVisibleAttribute(
true)] 


调用的函数:

webBrowser1.Document.InvokeScript("ShopXG"new string[] {"sss"}); 

JS中调用C#函数示例:
C#函数如下:

Code


JS里的调用方法:

Code

本篇为收藏篇,不记得是哪位大侠的了,请见谅