죄송합니다. 당신은 나에게 물건을 설명해야합니다, 나는 새로운 물을 밟고 있어요. 나는 자바에서 배경을 가지고 있지만 대부분 PHP, 자바 스크립트. 최상위 프레임 감지하기 BHO
http://www.codeproject.com/Articles/19971/How-to-attach-to-Browser-Helper-Object-BHO-with-C
내가 내 자신의 몇 가지 수정이 글을 따라 내 질문에 구체적이고, 나는 부모 문서 즉, 웹 페이지의 "최상위 프레임"을 감지 할 방법에 대해 설명합니다.OnDocumentComplete
에서 실행되는 코드는 페이지의 iframe이 모두 완료 될 때 실행됩니다.
내 기능과 구현 한 솔루션이 실제로 정확한 결과를 산출하지 않습니다.
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 페이지로드시 여러 웹 요청과 팝업으로 끝납니다.
CComQIPtr<IServiceProvider> pServiceProvider(pUnkSite);
if (!pServiceProvider) {
return E_FAIL;
}
pServiceProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID*)&m_WebBrowser.p);
if (!m_WebBrowser) {
return E_FAIL;
}
이이 저장됩니다 :
감사합니다. CComQIPtr을 어떻게 사용합니까? 어떤 어셈블리를 참조해야합니까? – thefoyer
http://msdn.microsoft.com/en-us/library/wc177dxw(v=vs.80).aspx를 참조하십시오. atlcomcli.h를 포함하면됩니다. –
아,하지만 C#을 사용하고 있다면 그냥 정상적인 캐스트를 사용할 수 있습니다. –