[英]Determining OnBeforeNavigate2 source
OnBeforeNavigate2
event occurs multiple times for a single document. OnBeforeNavigate2
事件针对单个文档发生多次。 The document I am loading contains iframe
so that triggers OnBeforeNavigate2
event multiple times.我正在加载的文档包含iframe
以便多次触发OnBeforeNavigate2
事件。
What I want to do is to figure out which frame triggered it and cancel the navigation if frame triggered it, and not a user-click.我想要做的是找出哪个框架触发它并在框架触发它时取消导航,而不是用户单击。
I am somewhat sure that I need to handle pDisp
parameter to determine the frame source and if it is with NULL parent or with browser parent - code would do something like that:我有点确定我需要处理pDisp
参数来确定帧源,如果它是 NULL 父级或浏览器父级 - 代码会做这样的事情:
void __fastcall TForm1::EmbeddedWBBeforeNavigate2(TObject *ASender, const IDispatch *pDisp,
OleVariant &URL, OleVariant &Flags, OleVariant &TargetFrameName, OleVariant &PostData,
OleVariant &Headers, WordBool &Cancel)
{
// This code is supposed to do that... (not in C++)
//var thisBrowser = pDisp as SHDocVw.WebBrowser;
//var parent = thisBrowser.Parent as SHDocVw.WebBrowser;
//bool isFrame = (parent == thisBrowser || parent == null);
...
}
I need help in figuring out the above and translating to C++ Builder.我需要帮助来弄清楚上述内容并将其转换为 C++ Builder。 If the above is the solution.如果以上是解决方案。 Or if it is not - the way to figure out how to determine if frame or iframe triggered this event or the user-click.或者如果不是 - 找出如何确定框架或 iframe 是否触发了此事件或用户单击的方法。
Update: (for future googlers)更新:(对于未来的谷歌员工)
I found some other solutions to this:我找到了其他一些解决方案:
bool IsFrame = (EmbeddedWB->ControlInterface != pDisp);
Original post - How do I avoid the OnDocumentComplete event for embedded iframe elements?原帖 - 如何避免嵌入 iframe 元素的 OnDocumentComplete 事件?
Try this:尝试这个:
void __fastcall TForm1::EmbeddedWBBeforeNavigate2(TObject *ASender, const IDispatch *pDisp,
OleVariant &URL, OleVariant &Flags, OleVariant &TargetFrameName, OleVariant &PostData,
OleVariant &Headers, WordBool &Cancel)
{
_di_IWebBrowser thisBrowser = pDisp;
_di_IWebBrowser parent = thisBrowser->Parent;
bool isFrame = ((!parent) || (parent == thisBrowser));
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.