问题
I am using geckofx-22 in my WPF app. I want to check the current url of the page which is loaded in the geckofx control. Can't find any property for the same.
回答1:
Try GeckoWebBrowser.Url
GeckoFx uses the nsIWebNavigation interface to implement this.
回答2:
Use the below code for WPF and place it in Geckofx-WPF GeckoWebBrowser.cs
/// <summary>
/// Gets the <see cref="Url"/> currently displayed in the web browser.
/// Use the <see cref="Navigate(string)"/> method to change the URL.
/// </summary>
[BrowsableAttribute(false)]
public Uri Url
{
get
{
if (_webNav == null)
return null;
nsIURI locationComObject = _webNav.GetCurrentURIAttribute();
var uri = locationComObject.ToUri();
Xpcom.FreeComObject(ref locationComObject);
return uri ?? new Uri("about:blank");
}
}
You can then access the url as
geckoWebbrowser.Url;
来源:https://stackoverflow.com/questions/21263271/geckofx-get-loaded-page-url