IE 自动化:如何确定用户启动的导航何时正在发生/已经发生?
我有一个 Internet Explorer BHO(在 c# .net 中),想要识别用户何时启动导航,或者用户启动的导航何时完成。 我所说的“用户发起”是指单击链接或类似操作。 特别是如果正在加载的文档中有多个框架,我想将它们视为单个“导航”,但我想不出任何简单的方法来做到这一点。 我知道 BeforeNavigate2 和 DocumentComplete 事件,但看不到任何方法来区分用户单击链接时触发的 BeforeNavigate/DocumentComplete 事件和由于加载框架而触发的事件。
我想到的一种可能的解决方案是,顶部框架的 BeforeNavigate2 总是在内部框架之前触发(显然),然后子框架的 DocumentComplete 在顶部的 DocumentComplete 之前被调用,而顶部框架总是最后调用。 例如,我可以在 BeforeNavigates 中增加一个计数器,并在 DocumentComplete 中减少它,只有当它为 0 时,它才是用户启动的导航。
但我不确定我是否可以依靠这个或者是否有更好的方法来做到这一点。 例如,如果用户在其中一帧但并非所有帧都完成加载后按 ESC,会发生什么情况:顶部帧的 DocumentComplete 是否会被调用?
有什么建议么?
I have an Internet Explorer BHO (in c# .net) and want to identify either when a user initiates a navigation, or when a user-initiated navigation has completed. By user-initiated I mean clicking on a link or similar action. In particular if there are multiple frames in the document being loaded I want to treat them as a single 'navigation', but I can't think of any easy way to do this. I know the BeforeNavigate2 and DocumentComplete events, but can't see any way to differentiate between BeforeNavigate/DocumentComplete firing when a user has clicked on a link and it firing because a frame is loading.
One possible solution I'm thinking is that the BeforeNavigate2 for the top frame always gets fired before that of the inner frames (obviously), and then the DocumentComplete of the child frames get called before the DocumentComplete of the top, which is always called last. So for instance I could increment a counter in BeforeNavigates and decrement it in DocumentComplete, and only when it's 0 is it a user-initiated navigation.
But I'm not sure if I can rely on this or if there's a better way to do it. e.g. What happens if the user presses ESC after one of the frames but not all have finished loading: does the DocumentComplete of the top frame ever get called?
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过针对您存储在 SetSite 中的浏览器对象指针测试 pDispParams 参数来测试 BeforeNavigate/NavigateComplete/DocumentComplete 事件是否来自 ineere 框架或最顶层的事件 你的 BHO 方法。
下面是执行此操作的 C++ 代码,我希望您可以轻松地将其转换为 C#:
webBrowser2 是指向您在 SetSite 方法中获得的浏览器对象的指针,
You can test whether BeforeNavigate/NavigateComplete/DocumentComplete event came from ineere frame or the topmost one simple by testing pDispParams agruments against pointer to browser object you have stored in SetSite method of your BHO.
Here's C++ code to do this, I hope you can convert it easily to C#:
webBrowser2 is pointer to browser object that you got in SetSite method,