如何避免嵌入式iframe元素的OnDocumentComplete事件? [英] How do I avoid the OnDocumentComplete event for embedded iframe elements?

查看:140
本文介绍了如何避免嵌入式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.

推荐答案

事件 OnDocumentComplete 被触发每个 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浏览器中时,编写一个OnDocumentComplete事件处理程序来采取特定的操作。对于没有框架的文档,当文档完成加载时,此事件会发生一次。在包含多个帧的文档上,该事件对于每个帧发生一次。多画面文档完成加载时,Web浏览器会最后一次触发该事件。

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.

发件人是加载文档的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事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆