其实还是还是相当的简单,本文将详细的用代码来展示一下如何调用,并且送上源代码。
这个主题,其实我是在QQ问问里看到的,那为Q友送上了380分,所以就写做了这样的一个DEMO。同时这里也分享给更多正在寻找与此相关的朋友的。
C#代码:
EXFCODE:
01
02
public
partial
class
Form1 : Form
03
{
04
public
Form1()
05
{
06
InitializeComponent();
07
}
08
private
void
Form1_Load(
object
sender, EventArgs e)
09
{
10
button4_Click(
null
,
null
);
11
}
12
//显示普通网页
13
private
void
button4_Click(
object
sender, EventArgs e)
14
{
15
webBrowser1.Navigate(
"http://www.exfsoft.com/demo/qqww1229/exf.htm"
);
16
}
17
//执行普通网页的JS方法
18
private
void
button1_Click(
object
sender, EventArgs e)
19
{
20
try
21
{
22
webBrowser1.Document.InvokeScript(
"doSave"
,
new
object
[] {
"Winform普通:"
});
23
}
24
catch
{ }
25
}
26
//显示框架页
27
private
void
button5_Click(
object
sender, EventArgs e)
28
{
29
webBrowser1.Navigate(
"http://www.exfsoft.com/demo/qqww1229/main.htm"
);
30
}
31
//执行框架页中的JS方法
32
private
void
button2_Click(
object
sender, EventArgs e)
33
{
34
try
35
{
36
webBrowser1.Document.Window.Frames[
"mainFrame"
].Document.InvokeScript(
"doSave"
,
new
object
[] {
"Winform框架:"
});
37
}
38
catch
{ }
39
}
40
}
网页代码,由于是测试了两种模式,所以这里用了两个网页。
子网页:exf.htm
EXFCODE:
01
<
html
>
02
<
head
>
03
<
title
>exfosft</
title
>
04
<
meta
name
=
"author"
content
=
"玄峰"
/>
05
<
meta
name
=
"QQ"
content
=
"4513427"
/>
06
<script type="text/javascript">
07
function
doSave(type)
08
{
09
alert(type +
"执行的该事件。"
);
10
}
11
</script>
12
</
head
>
13
<
body
>
14
<
form
name
=
"form1"
id
=
"form1"
>
15
<
table
style
=
"width:100%;"
>
16
<
tr
>
17
<
td
onclick
=
"doSave('WEB')"
style
=
"cursor:pointer;"
><
img
src
=
"save.png"
align
=
"absMiddle"
> 保存</
td
>
18
</
tr
>
19
</
table
>
20
</
form
>
21
</
body
>
22
</
html
>
框架页:
EXFCODE:
1
<
html
>
2
<
head
>
3
<
title
>exfsoft.com</
title
>
4
</
head
>
5
<
frameset
rows
=
"10%,50%"
>
6
<
frame
name
=
top
src
=
"http://www.exfsoft.com"
>
7
<
frame
name
=
"mainFrame"
src
=
"exf.htm"
>
8
</
frameset
>
9
</
html
>
运行效果为: