简体   繁体   中英

Cefsharp how to get current URL address? c#

I want to get the current address and basically put it in a textbox. I found this link but can't seem to understand anything.

http://cefsharp.github.io/api/57.0.0/html/P_CefSharp_WinForms_ChromiumWebBrowser_Address.htm

I would really appreciate a code snippet from someone. It's killing me. i'm using WFA.

You have to listen to below address change event and persists it yourself.

this.Browser = new ChromiumWebBrowser();
this.Browser.AddressChanged += Browser_AddressChanged;

private void Browser_AddressChanged(object sender, AddressChangedEventArgs e)
        {
            this.CurrentAddress = e.Address;
        }

I'm using version 71 and the method:

TextBox1.Text = browser.Address;

Seems to work. Try updating to 71 and see if that helps, if you still have a problem with this.

"browser" is obviously the CefSharp browser control I've added programmatically. If you don't know how to do this, it's merely the following:

CefSharp.WinForms.ChromiumWebBrowser browser = new CefSharp.WinForms.ChromiumWebBrowser("https://google.com/");

The browser object exposes the address using the property Address :

var browser = new ChromiumWebBrowser(...);
var currentAddress = browser.Address;

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