Search code examples
c#httpbrowsertextboxgeckofx

C# GeckoFX web browser - Remove http from textbox


I'm working on a web browser. Once the textbox isn't selected anymore it should remove http:// and the last /. To do that I'm using the leave method of the textbox. This code works perfectly fine with the normal WebBrowser.

        if (W.DocumentTitle != "")
        {
            q.Text = "" + W.Url;
            q.Text = q.Text.Replace("http://www.", "");
            q.Text = q.Text.Replace("https://www.", "");
            q.Text = q.Text.Replace("http://", "");
            q.Text = q.Text.Replace("https://", "");
            if (q.Text.EndsWith("/"))
            {
                q.Text = q.Text.Substring(0, q.Text.Length - 1);
            }
        }

In GeckoFX however the textbox still displays http:// and /!?!?!


Solution

  • if you want take only domain name try this

    q.Text = myGeckoWebBrowser.Url.Domain;
    

    If you want only the local path try this

    q.Text = myGeckoWebBrowser.Url.LocalPath;
    

    And if you want both try this

    q.Text = myGeckoWebBrowser.Url.Domain + '' + myGeckoWebBrowser.Url.LocalPath;
    q.Text = q.Text.Replace("www","")'
    

    I hope it helps