正确的方法去拦截OnNewWindow2实现在同一个窗口显示_target的网页
2014-10-13 11:53
134 查看
[cpp] view
plaincopy
// 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);
}
plaincopy
// 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的网页
- 正确的方法去拦截OnNewWindow2实现在同一个窗口显示_target的网页
- 正确的方法去拦截OnNewWindow2实现在同一个窗口显示_target的网页
- javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法
- javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法
- 实现一个用于显示当前时间的Google Android 窗口小部件(AppWidget) 推荐
- 实现一个用于显示当前时间的Google Android 窗口小部件(AppWidget)
- 让js弹出窗口居前显示的实现方法
- 用JavaScript的正则表达式验证网址格式是否正确,方法很多,这只是一个实现的方法.
- 用按钮控制iframe显示的网页实现方法
- 禁用IE的后退按钮|显示网页已过期|几种语言的实现方法|c#|javascript|html
- 实现一个用于显示当前时间的Google Android 窗口小部件
- 如何在mfc对话框中添加一个显示网页的窗口
- 如何在mfc对话框中添加一个显示网页的窗口 .
- 怎么弹出一个既不会被拦截,又是window.open方式实现的最大化弹出窗口?
- 在mfc对话框中添加一个显示网页的窗口
- 禁用IE的后退按钮|显示网页已过期|几种语言的实现方法|c#|javascript|html
- 用JS实现的网页关键字高亮显示的方法
- 鼠标移到某个字上显示出一个文本框(prototype实现方法)
- js+数组实现网页上显示时间/星期几的实用方法