我怎样才能从Chrome和Firefox打开的页面的网址吗? [英] How can I get URLs of open pages from Chrome and Firefox?

查看:362
本文介绍了我怎样才能从Chrome和Firefox打开的页面的网址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写需要检查,如果内部Web应用程序的基础是开放的系统托盘中的应用程序。

I'm writing a system tray app that needs to check if an internal web based app is open.

我可以使用下面的检查IE浏览器:

I can check IE using the following:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
        string filename;
        bool sdOpen = false;
        foreach (SHDocVw.InternetExplorer ie in shellWindows)
        {
            filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
            if (filename.Equals("iexplore"))
            {
                string[] urlParts = (ie.LocationURL.ToString()).Split('/');
                string website = urlParts[2];
                if (website == "myApp:8080") { sdOpen = true; };
            }
        }

        if (sdOpen) { Console.WriteLine("App is open"); } else { Console.WriteLine("App is not open"); };

        Console.ReadKey(true);

然而,一些使用该系统preFER Chrome或Firefox的用户。

However, some of the users using the system prefer Chrome or Firefox.

我怎样才能做到与上面相同(即获得在任何浏览器中打开的选项卡中的URL)的Chrome和Firefox? (我不打算与其他浏览器来打扰,因为这些是唯一的,在我们的组织中使用。)

How can I do the same as above (i.e. get the urls of any open tabs in the browser) for Chrome and Firefox? (I'm not going to bother with other browsers as these are the only ones in use in our organisation.)

推荐答案

这是具体的每一个浏览器。这对于主要的:

It's specific for every browser. That's for the major ones:


  • 的Internet Explorer - 您可以使用SHDOCVW(像你这样)

  • 火狐 - 您可以使用DDE(下文源)获取URL

  • Chrome浏览器 - 你可以得到URL,而枚举所有子窗口,直到你能带班Chrome_OmniboxView控制,然后用得到的文本 GetWindowText时

  • 歌剧 - 您可以使用同样的事情,火狐,但与歌剧

  • Safari浏览器 - 没有已知的方法,因为它使用了自定义绘制控件

  • Internet Explorer - You can use SHDocVw (like you did)
  • Firefox - You can get the URL using DDE (source below)
  • Chrome - You can get the URL while enumerating all the child windows untill you get to the control with class "Chrome_OmniboxView" and then get the text using GetWindowText
  • Opera - You can use the same thing as Firefox, but with "opera"
  • Safari - There is no known method since it uses custom drawn controls

编辑:自2014年,Chrome已经改变,你需要得到与Acessibility的网址

code。使用DDE获得从Firefox /歌剧的URL(它使用 NDDE - 唯一的好DDE为包装.NET):

Code to get the URL from Firefox/Opera using DDE (which used NDDE - the only good DDE wrapper for .NET):

//
// usage: GetBrowserURL("opera") or GetBrowserURL("firefox")
//

private string GetBrowserURL(string browser) {
    try {
        DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo");
        dde.Connect();
        string url = dde.Request("URL", int.MaxValue);
        string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
        dde.Disconnect();
        return text[0].Substring(1);
    } catch {
        return null;
    }
}

这篇关于我怎样才能从Chrome和Firefox打开的页面的网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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