OnBeforeNavigate2
event occurs multiple times for a single document. The document I am loading contains iframe
so that triggers OnBeforeNavigate2
event multiple times.
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:
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. 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.
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?
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));
...
}