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!
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.
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.
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/
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.