且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用c#获取当前活动的IE URL?

更新时间:2023-02-21 17:10:49

没有活动URL这样的东西。每个浏览器窗口只能导航到一个URL,每个窗口都是活动URL。



你所指的是哪个窗口有输入焦点。 ShellWindow类不跟踪它。



您可以使用GetForegroundWindow [ ^ ]函数获取具有输入焦点的窗口的句柄。然后,如果您枚举通过调用 Process.GetProcessesByName() [ ^ ]并查找iexplorer.exe。
There is no such thing as an "Active URL". Every browser window can only navigate to one URL, and every window is the "Active URL".

What you're referring to is which window has the input focus. The ShellWindow class does not track that.

You can use the GetForegroundWindow[^] function to get the handle to the window that has the input focus. You can then compare that handle to the window handles you get if you enumerate over the list of processes you get from calling Process.GetProcessesByName() [^]and look for "iexplorer.exe".


http://***.com/questions/4173982/c-尖锐的 - 如何获得当前的url-from-the-ie [ ^ ]


using System.IO;

...

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();

string filename;

foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
    filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();

    if ( filename.Equals( "iexplore" ) )
        Console.WriteLine( "Web Site   : {0}", ie.LocationURL );

    if ( filename.Equals( "explorer" ) )
        Console.WriteLine( "Hard Drive : {0}", ie.LocationURL );
}