Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 341
CsgoTalks Com Avatar asked Jun 26 '17 12:06

CsgoTalks Com


3 Answers

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;
        }
like image 180
Pravin Avatar answered Oct 07 '22 09:10

Pravin


The browser object exposes the address using the property Address:

var browser = new ChromiumWebBrowser(...);
var currentAddress = browser.Address;
like image 25
Chrille Avatar answered Oct 07 '22 11:10

Chrille


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/");
like image 2
w60 Avatar answered Oct 07 '22 11:10

w60