Geckofx get loaded page url

此生再无相见时 提交于 2019-12-24 12:38:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!