Cefsharp how to get current URL address? c#
Asked Answered
P

3

8

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.

Peggypegma answered 26/6, 2017 at 12:44 Comment(2)
Please share your efforts so far, some code for example.Nitrochloroform
I have the browser that's working fine puu.sh/wuFOg/3ac3a28bda.png Thing is, I want to verify if the link is redirected to one place or another = if the user is logger in or not. (it's a bit weird :) )Peggypegma
V
7

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;
        }
Vanhouten answered 24/10, 2017 at 19:3 Comment(1)
There doesn't appear to be an "AddressChanged" event in the latest version for me..?Aleras
N
2

The browser object exposes the address using the property Address:

var browser = new ChromiumWebBrowser(...);
var currentAddress = browser.Address;
Nitrochloroform answered 26/6, 2017 at 12:53 Comment(3)
I did not found the browser.Address property on version 57, is it on older versions.Vanhouten
@Pravin: It should still be avaliable in version 57: cefsharp.github.io/api/57.0.0/html/…Nitrochloroform
@Nitrochloroform There is no property called Address in version 67, how to get the DocumentComplete like webbrowser.Haydon
D
2

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/");
Delmore answered 10/2, 2019 at 1:52 Comment(1)
I don't see it in the Intellisense dropdown, but the property is there. Must have the Browsable(False) property attribute.Charolettecharon

© 2022 - 2024 — McMap. All rights reserved.