如何使用c#获取当前活动的IE URL? [英] How to get current active IE url using c# ?

查看:158
本文介绍了如何使用c#获取当前活动的IE URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个代码来获取当前即来自浏览器的URL

Hi, I did a code to get current ie URL from ie browser

foreach (InternetExplorer ie in new ShellWindows())
{
   label1.Text = ie.LocationURL.ToString();
   label2.Text = ie.LocationName.ToString();
}



但显示上次打开的网址而不是有效网址。

那么,如何修改我的代码以从浏览器获取当前活动的URL?

谢谢。







添加标签。

[/编辑]

推荐答案

没有活动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://stackoverflow.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 );
}


这篇关于如何使用c#获取当前活动的IE URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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