免嵌入式iframe元素的OnDocumentComplete事

免嵌入式iframe元素的OnDocumentComplete事

本文介绍了如何避免嵌入式iframe元素的OnDocumentComplete事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想防止 iframe 元素每次触发 OnDocumentComplete 事件。例如,页面有4个iframe,当我加载此页面时,我的 OnDocumentComplete 事件运行4次。我想为每个页面运行一次 OnDocumentComplete 。我可以这样做吗?

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?

也许我可以删除或阻止 iframe TWebBrowser control。

Maybe I could remove or block iframes in TWebBrowser control.

推荐答案

事件被触发每个 FRAME / IFRAME 在主文档中。

如果您想忽略它们,请尝试以下操作:

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;






来自Delphi文档:


From Delphi Docs:

发件人是加载文档的Web浏览器。

Sender is the Web browser that is loading the document.

pDisp是顶级框架或浏览器的自动化界面。
加载没有框架的文档时,pDisp是
Web浏览器的界面。当加载具有多个帧的文档时,这是包含框架的
接口,除了最后一次
事件发生时,它是Web浏览器的接口。

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.

这篇关于如何避免嵌入式iframe元素的OnDocumentComplete事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:20