简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM