tags:

views:

2380

answers:

6
+2  Q: 

Get Firefox URL?

How can I get the url from a running instance of firefox using .NET 2.0 windows/console app? C# or VB codes will do.

Thanks!

+1  A: 

You may want to check into the source code of WatiN. Their next version is open source and supports firefox, so I would imagine the functionality for doing this is in it.

Jeff Martin
I've edited the question to add more details. I'm doing a winforms application and i need to get the browser URL. I already have the codes for the IE Url. Thanks!
Leon Tayson
+2  A: 

it seems that this might be difficult, here's some discussion on it: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c60b1699-9fd7-408d-a395-110c1cd4f297/

John Boker
+3  A: 

For most browsers, including Internet Explorer, Navigator, Firefox, and Opera, the supported and sanctioned way of doing this is to use DDE. The topic name in all of them is WWW_GetWindowInfo; only the name of the target window varies. That technique will be difficult for you, though, because .Net doesn't support DDE. If you can find a way to get around that limitation, you'll be all set.

Rob Kennedy
DDE library for .NET: http://www.codeplex.com/ndde
Foole
+1  A: 

Poor man's solution, if anything else fails: activate the Firefox window, send Ctrl+L (activates address bar), send Ctrl+C (copy selection, ie. URL, to clipboard) and read the clipboard.

Lot of issues with this method (among them it does strange stuff for the user if they are in front of the computer) so it is only a backup solution...

PhiLho
hiii Can you tell me how to send keys using c#.net???
ankush
No. Because I don't know C#. I would do that with AutoHotkey... :-P
PhiLho
A: 

Leon mentioned that he was able to get this working using .NET 3.5. Can anyone point me in the right direction for this solution? Thank you,

  • G
ghawkes
+2  A: 

Building on Rob Kennedy's answer and using NDde

using NDde.Client;

class Test
{
        public static string GetFirefoxURL()
        {
            DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
            dde.Connect();
            string url = dde.Request("URL", int.MaxValue);
            dde.Disconnect();
            return url;
        }
}

NB: This is very slow. It takes a few seconds on my computer. The result will look something like this :

"http://stackoverflow.com/questions/430614/get-firefox-url","Get Firefox URL? - Stack Overflow",""

More info on browser DDE here.

Foole