2

我正在开发 Windows Phone PhoneGap 应用程序。我可以知道如何获取 PhoneGap 的 webview 的当前 URL 吗?

4

1 回答 1

1

我通过以下this.CordovaView.Browser.Navigated += Browser_Navigated;Browser_Navigated函数处理事件来实现目标。

private void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            Console.WriteLine("Browser_Navigated:" + sender);

            String currentURL = "";
            Boolean isAbsolute = this.CordovaView.Browser.Source.IsAbsoluteUri;
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode =ApplicationBarMode.Minimized;
            if (isAbsolute)
            {
                currentURL = this.CordovaView.Browser.Source.AbsoluteUri;



                ApplicationBarMenuItem clearCache = new ApplicationBarMenuItem();
                clearCache.Text = "Reset user settings";
                ApplicationBar.MenuItems.Add(clearCache);
                clearCache.Click += new EventHandler(OnClearCache);

                if (! currentURL.EndsWith("LoginSP.aspx")) 
                {
                    ApplicationBarMenuItem logOut = new ApplicationBarMenuItem();
                    logOut.Text = "Log out";
                    ApplicationBar.MenuItems.Add(logOut);
                    logOut.Click += new EventHandler(OnLogOut);
                }
            }
            else
            {
                currentURL = "x-wmapp1:" + this.CordovaView.Browser.Source.OriginalString;
                ApplicationBar.IsVisible = false;
            }

            Console.WriteLine("currentURL:" + currentURL);
        }

参考:https ://github.com/dev-mobile/cordova-starter/blob/master/win7_cordova_starter/wp7_CordovaStarter/MainPage.xaml.cs

于 2013-08-23T11:12:19.197 回答