webbrowser获取带有alert提示的网页的源码.

dancecat120 2008-06-10 10:43:46
我的代码如下:

private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
if (_ActiveWebBrowser.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
HE_WebBrowserTag _HE_WebBrowserTag = (HE_WebBrowserTag)_ActiveWebBrowser.Tag;
if (_HE_WebBrowserTag._TabIndex == tabControl1.SelectedIndex)
{
txbURLLocation.Text = _ActiveWebBrowser.LocationURL;
}
WebBrowserViewSource();//获取网页源代码
}
}


现在有一个问题.网页中有时有一个alert谈出窗口.必须要手动点击确定后.才能读出源码.有没有办法.不点击确定直接读到网页的值.我想要得到alert里的提示信息

网页中的值如:

<script>alert('已成功登录');</script>
<body>
<table>
...
怎样才能不手动点击确实得到alert中的值
...全文
836 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovefootball 2008-06-10
  • 打赏
  • 举报
回复
HtmlDocument doc = .......;
IHTMLWindow2 win = (IHTMLWindow2)doc.Window.DomWindow;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";

s += @"function alert() {}";

win.execScript(s, "javascript");
dancecat120 2008-06-10
  • 打赏
  • 举报
回复
继续等!
net135 2008-06-10
  • 打赏
  • 举报
回复
期待答案
fengyecsdn 2008-06-10
  • 打赏
  • 举报
回复
AxInterop.SHDocVw.dll
Interop.SHDocVw.dll
你可能需要引用这两个DLL
fengyecsdn 2008-06-10
  • 打赏
  • 举报
回复
替换脚本.首先要找到ALERT的脚本方法名.然后把它顶替掉.

我一般都是直接 写一个脚本方法 名字就叫 ALERT(),然后里边记录动作,而不弹出框.



using mshtml;

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
textBox1.Text += "\r\n WB DCOM\r\n";
//webBrowser1.DocumentText = webBrowser1.DocumentText.Replace("window.open", "").Replace("window.Open", "");
IHTMLDocument2 vDo = (IHTMLDocument2)webBrowser1.Document.DomDocument;
// vDo.parentWindow.execScript("function alert(str){ window.external.HaHa(str); } var wnd=window; function window2() { this.win=wnd; this.open=function(url, target, params) { window.external.HaHa(url); }; this.unload=function() { window.external.HaHa('Out ing OK'); }; } var hjhj=new window2(); hjhj.open('http://www.baidu.com','haha','jiba'); alert('hahabubububu'); ", "javaScript");
vDo.parentWindow.execScript("function alert(str){ window.external.HaHa(str); } function window.open(url, target, params) { window.external.HaHaopen(url , target); }; function window.unload() { window.external.HaHaunld(); } ; function window.close() { window.external.HaHaclose(); } ; function window.onunload() { window.external.HaHaunld(); }; function window.onbeforeunload() { window.external.HaHaunld(); }; function cls(){ window.external.HaHaunld(); }; alert('hahabubububu'); ", "javaScript");

}

public void HaHa(string haha)
{
textBox1.Text += " \r\n ★★★★★★★★★★ \r\n==WB Get Message== \r\n " + haha + "\r\n";
}
public void HaHaopen(string url,string tager)
{
textBox2.Text += " \r\n ★★★★★★★★★★ \r\n==WB Get NewWind== \r\n URL:" + url+" TAG:"+tager+ "\r\n";
SBisDO = true;
if (url.ToLower().Substring(0, 4) == "/eip")
{
webBrowser2.Navigate("http://app.xxml.com.cn" + url,false);
}
}
public void HaHaclose()
{
textBox1.Text += " \r\n ★★★★★★★★★★ \r\n==WB Get close== \r\n \r\n";
}
public void HaHaunld()
{
textBox1.Text += " \r\n ★★★★★★★★★★ \r\n==WB Get UnLoading== \r\n \r\n";
}

private void webBrowser1_FileDownload(object sender, EventArgs e)
{
textBox1.Text += "WB is FILE DOWN \r\n";
}

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
textBox1.Text += "WB is Naving "+e.Url.ToString() +" == "+e.TargetFrameName+"\r\n";
}

lovefootball 2008-06-10
  • 打赏
  • 举报
回复
你的让弹出alert的那个window来执行这段JS
dancecat120 2008-06-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jinjazz 的回复:]
就是用自定义的js函数把系统的那个干掉
[/Quote]



IHTMLDocument2 vDocument = (IHTMLDocument2)mybrowser.Document.DomDocument;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";
s += @"function alert() {}";
vDocument.parentWindow.execScript(s, "javascript");



改成这样.执行效果是一样的.还是会弹出alert.
jinjazz 2008-06-10
  • 打赏
  • 举报
回复
就是用自定义的js函数把系统的那个干掉
dancecat120 2008-06-10
  • 打赏
  • 举报
回复
看不明白.能不能解释一下呢

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧