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

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

也许我可以删除或阻止 TWebBrowser 控件中的 iframes.

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:

编写一个 OnDocumentComplete 事件处理程序,以便在框架或文档完全加载到 Web 浏览器中时采取特定操作.对于没有框架的文档,该事件在文档加载完成时发生一次.在包含多个框架的文档上,此事件针对每个框架发生一次.当多帧文档完成加载时,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浏览器的界面.

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天全站免登陆