Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Please show me how to get url form any web browser or any application
if you have source code,please give it for me!
Posted
Updated 5-Apr-18 12:25pm

You Can do that by monitoring http urls requests from your system.
It will monitor any url from any browser. More Information here:

http://stackoverflow.com/questions/924449/how-to-create-a-simple-c-sharp-http-monitor-blocker[^]
 
Share this answer
 
 
Share this answer
 
Get the URl From Firefox and Opera :

C#
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);
 
Download NDde dll and add reference, and use as name space
 
//===========Get URL of All Tabs From IE ======================
 
SHDocVw.InternetExplorer browser;
string myLocalLink;
mshtml.IHTMLDocument2 myDoc;
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
string filename;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if ((filename == "iexplore"))
{
browser = ie;
myDoc = browser.Document;
myLocalLink = myDoc.url;
MessageBox.Show(myLocalLink);
}
 
Share this answer
 
v2
Comments
Akshay3839 18-Oct-16 7:38am    
firefox:

this code block works for old firefox version.. but when firefox update to 49.0 it is not working... plz help me
you can get the current page url using following code,

C#
Request.Url.AbsoluteUri.ToString()
 
Share this answer
 
public string GetChormeURL(string ProcessName)
{
    string ret = "";
    Process[] procs = Process.GetProcessesByName(ProcessName);
    foreach (Process proc in procs)
    {
        // the chrome process must have a window
        if (proc.MainWindowHandle == IntPtr.Zero)
        {
            continue;
        }
        //AutomationElement elm = AutomationElement.RootElement.FindFirst(TreeScope.Children,
        //         new PropertyCondition(AutomationElement.ClassNameProperty, "Chrome_WidgetWin_1"));
        // find the automation element
        AutomationElement elm = AutomationElement.FromHandle(proc.MainWindowHandle);

        // manually walk through the tree, searching using TreeScope.Descendants is too slow (even if it's more reliable)
        AutomationElement elmUrlBar = null;
        try
        {
            // walking path found using inspect.exe (Windows SDK) for Chrome 43.0.2357.81 m (currently the latest stable)
            // Inspect.exe path - C://Program files (X86)/Windows Kits/10/bin/x64
            var elm1 = elm.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Google Chrome"));
            if (elm1 == null) { continue; } // not the right chrome.exe
            var elm2 = TreeWalker.RawViewWalker.GetLastChild(elm1); // I don't know a Condition for this for finding
            var elm3 = elm2.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, ""));
            var elm4 = TreeWalker.RawViewWalker.GetNextSibling(elm3); // I don't know a Condition for this for finding
            var elm5 = elm4.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar));
            var elm6 = elm5.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, ""));
            elmUrlBar = elm6.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
        }
        catch
        {
            // Chrome has probably changed something, and above walking needs to be modified. :(
            // put an assertion here or something to make sure you don't miss it
            continue;
        }

        // make sure it's valid
        if (elmUrlBar == null)
        {
            // it's not..
            continue;
        }

        // elmUrlBar is now the URL bar element. we have to make sure that it's out of keyboard focus if we want to get a valid URL
        if ((bool)elmUrlBar.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty))
        {
            continue;
        }

        // there might not be a valid pattern to use, so we have to make sure we have one
        AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
        if (patterns.Length == 1)
        {
            try
            {
                ret = ((ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0])).Current.Value;
                return ret;
            }
            catch { }
            if (ret != "")
            {
                // must match a domain name (and possibly "https://" in front)
                if (Regex.IsMatch(ret, @"^(https:\/\/)?[a-zA-Z0-9\-\.]+(\.[a-zA-Z]{2,4}).*$"))
                {
                    // prepend http:// to the url, because Chrome hides it if it's not SSL
                    if (!ret.StartsWith("http"))
                    {
                        ret = "http://" + ret;
                    }
                    return ret;
                }
            }
            continue;
        }
    }
    return ret;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900