- // CMy5View message handlers
- #include <atlbase.h>
- #include <Mshtml.h>
- #include <COMDEF.H>
- void CMy5View::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
- {
- // TODO: Add your specialized code here and/or call the base class
- CComPtr<IHTMLDocument2> pHTMLDocument2;
- m_pBrowserApp->get_Document((IDispatch **)&pHTMLDocument2);
- if (pHTMLDocument2!=NULL)
- {
- CComPtr<IHTMLElement> pIHTMLElement;
- pHTMLDocument2->get_activeElement(&pIHTMLElement);
- if (pIHTMLElement!=NULL)
- {
- variant_t url;
- HRESULT hr=pIHTMLElement->getAttribute(L"href", 0, &url);
- if (SUCCEEDED(hr))
- {
- hr=m_pBrowserApp->Navigate2(&url, NULL, NULL, NULL, NULL);
- url.Clear();
- if (SUCCEEDED(hr))
- {
- *Cancel=TRUE;
- }
- }
- }
- }
- // CHtmlView::OnNewWindow2(ppDisp, Cancel);
- }
正确的方法去拦截OnNewWindow2实现在同一个窗口显示_target的网页
猜你喜欢
转载自blog.csdn.net/yaowang107/article/details/79363163
今日推荐
周排行