其實還是還是相當的簡單,本文將詳細的用代碼來展示一下如何調用,並且送上原始碼。
這個主題,其實我是在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
>
運行效果為: