How to avoid the OnDocumentComplete event for inline iframes?

I want iframe elements not to OnDocumentComplete event every time. For example, a page has 4 frames, and when I load this page, my OnDocumentComplete event fires 4 times. I want to run OnDocumentComplete only once for each page. How can i do this?

Perhaps I could remove or block iframes in the TWebBrowser control.

+6
source share
1 answer

The OnDocumentComplete event is OnDocumentComplete for each FRAME / IFRAME in the main document.
If you want to ignore them, try the following:

 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 perform certain actions when a frame or document is fully loaded into a web browser. For a document without frames, this event occurs once when the document finishes loading. In a document containing multiple frames, this event occurs once for each frame. When a document with multiple frames finishes loading, the web browser fires the event for the last time.

Sender is a web browser that downloads a document.

pDisp is a top-level frame or browser automation interface. When loading a document without frames, pDisp is the Web browser interface. When loading a document with multiple frames, this is the interface of the containing frame, with the exception of the last event that occurs when it is a web browser interface.

+14
source

Source: https://habr.com/ru/post/912927/


All Articles