2
对不起,我的无知。你必须向我解释一些事情,我正在新的水域中行走。我在JAVA有一些背景,但主要是PHP,JavaScript。检测顶层框架BHO
http://www.codeproject.com/Articles/19971/How-to-attach-to-Browser-Helper-Object-BHO-with-C
我跟着这篇文章我自己的一些修改和我的问题是具体如何做我检测网页的“顶层框架”,即父文档。我在OnDocumentComplete
执行任何代码运行时,页面上的任何I帧也都完成了。
我的功能,我实现了实际上不产生正确的结果的解决方案。
public class BHO:IObjectWithSite
{
WebBrowser webBrowser;
HTMLDocument document;
public void OnDocumentComplete(object pDisp, ref object URL)
{
document = (HTMLDocument)webBrowser.Document;
string href = document.location.href;
//get top level page
if (href == URL.ToString())
{
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://mysite.com");
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
byte[] buffer = Encoding.ASCII.GetBytes("string");
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
// Prepare web request and send the data.
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
StreamReader streamResponse = new StreamReader(WebResp.GetResponseStream(), true);
string Response = streamResponse.ReadToEnd();
Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(Response);
string active = json["active"].ToString();
//print to screen
System.Windows.Forms.MessageBox.Show(active, "Title");
}
}
检查是否匹配document.location.href
在大多数情况下URL
的作品,但不能保证。所以结果是我最终在1页加载时得到了多个web请求和弹出窗口。
感谢您的答复马修。我如何使用CComQIPtr,我必须参考哪些程序集? – thefoyer
见http://msdn.microsoft.com/en-us/library/wc177dxw(v=vs.80).aspx。你只需要包含atlcomcli.h。 –
啊,但如果你使用C#我猜你可以只使用一个普通演员。 –