I want to prevent iframe
elements from triggering the OnDocumentComplete
event every time. For example, a page has 4 iframes, and when I load this page, my OnDocumentComplete
event runs 4 times. I want to run OnDocumentComplete
just once for every page. How can I do that?
Maybe I could remove or block iframes
in TWebBrowser
control.
The event OnDocumentComplete
is fired for each FRAME
/IFRAME
in the main document.
If you want to ignore them try this:
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
// check that the event is raised for the top-level browser (not frames or iframes)
if pDisp = TWebBrowser(Sender).ControlInterface then
begin
// do something nice...
end;
end;
From Delphi Docs:
Write an OnDocumentComplete event handler to take specific action when a frame or document is fully loaded into the Web browser. For a document without frames, this event occurs once when the document finishes loading. On a document containing multiple frames, this event occurs once for each frame. When the multiple-frame document finishes loading, the Web browser fires the event one final time.
Sender is the Web browser that is loading the document.
pDisp is the Automation interface of the top-level frame or browser. When loading a document without frames, pDisp is the interface of the Web browser. When loading a document with multiple frames, this is the interface of the containing frame, except for the very last time the event occurs, when it is the interface of the Web browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With