网页代码
<html><head>
<title>链接</title>
</head><body><a id="test" href="Clicklink.htm">链接</a></body></html>
Windows程序C#语言如何自动完成点击链接?用代码 wbPage.Document.Links["test"].Click(),编译器提示下列错误:事件“System.Windows.Forms.HtmlElement.Click”只能出现在 += 或 -= 的左边
请问有管用的办法没?
<html><head>
<title>链接</title>
</head><body><a id="test" href="Clicklink.htm">链接</a></body></html>
Windows程序C#语言如何自动完成点击链接?用代码 wbPage.Document.Links["test"].Click(),编译器提示下列错误:事件“System.Windows.Forms.HtmlElement.Click”只能出现在 += 或 -= 的左边
请问有管用的办法没?
{
e.Cancel = true;
try
{
string url = this.webBrowser1.Document.ActiveElement.GetAttribute("href");
this.webBrowser1.Url = new Uri(url);
}
catch
{
}
}
参考
上述方法与webBrowser.Navigate(strUrl);的效果一样,无法满足我需要的效果。
现在的网页多是框架结构,一个链接获得的页面要放到<a target="rightfram">指明的子框架中,像上述代码与webBrowser.Navigate(strUrl),都无法满足这一动作要求。
继续求教中。
function openUrl(url)
{
this.location.href = url;
}
然后在程序里 Document.InvokeScript("openUrl", url) 试试,注意传递的url需要是数组
===index.htm===这是主页面,框架结构
<html><head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>主页面</title>
</head><frameset cols="*,*">
<frame name="left" src="left.htm">
<frame name="main">
<noframes>
<body> <p>此网页使用了框架,但您的浏览器不支持框架。</p> </body>
</noframes>
</frameset></html>===left.htm===框架左边的子页面的代码
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>在右边打开一个网页</title>
</head><body><p><a target="main" href="right.htm">在右边打开一个网页</a></p></body></html>
===right.htm===将在框架右边显示的子页面
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>我是由左边子页面打开的</title>
</head><body><p>我是由左边子页面打开的</p></body></html>
如果直接用
webBrowser.Navigate(strUrl);
webBrowser1.Url = new Uri(url);
……
等代码,
只会使当前webBrowser打开的是right.htm而不是index.htm
我的目标是当前webBrowser的开的页面仍是index.htm,而right.htm的内容只显示在index页面的框架右侧