以编程方式确定 IE 窗口当前 URL,无需 BHO
有人可以指导我如何在没有 BHO 的情况下以编程方式确定 IE 当前的 URL 吗?
我能够想到完成此类功能的唯一方法是查看窗口的标题而不是 URL,但这看起来很hacky。
另一方面,我假设存储 URL 的文本框有一个句柄,我可以附加该句柄并读取文本。我的这个假设正确吗?
任何指导将不胜感激。
PS:如果您能提供也适用于 Firefox 的示例/指南,则会加分。
编辑:好的,进一步的研究开始发现我需要查看的是 GetWindowText 和消息 WM_GETTEXT。如果我把这一切都解决了,我会发布答案。
Could someone guide me in the direction of how I would determine IE's current URL programmatically without a BHO?
The only way I have been able to think of accomplishing this sort of functionality is by looking at the title for the window rather then the URL but this seems hacky.
On the other hand I assume that the textbox that stores the URL would have a handle which I attach to and read the text. Am I correct in this assumption?
Any guidance would be appreciated.
PS: Bonus points if you can provide an example/guidance that will work with Firefox also.
EDIT: OK so further research is starting to uncover that what I need to look at is GetWindowText and the message WM_GETTEXT. If I get this all worked out will post answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

所以这是一篇非常旧的帖子,但我偶然发现了它,所以我想我会尝试回答它,因为我刚刚了解到这个:)
你可以使用 Windows Shell。您可以循环访问打开的窗口并查找任何“HTTPDocumentClass”对象(这些是 Internet Explorer 窗口),然后您可以访问 .LocationUrl 成员来查找 URL。
我不知道如何用 C# 编写示例,但以下是用 VB 编写的示例。
注意:您需要添加对Microsoft Shell 控件和自动化和Microsoft Internet 控件的引用。
So this is a REALLLLLY old post, but I stumbled upon it so figured I would attempt to answer it since I just learned this :)
You can do it using the Windows Shell. You can iterate through the open windows and look for any "HTTPDocumentClass" object (these are Internet Explorer windows) and then you can access the .LocationUrl member to find out the URL.
I don't know how to write an example in C#, but here's how you do it in VB.
NOTE: You need to add references to Microsoft Shell Controls and Automation and Microsoft Internet Controls.