Windows Phone PhoneGap应用程序中webview的当前URL

时间:2013-08-22 09:44:01

标签: c# windows-phone-8 cordova

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

1 个答案:

答案 0 :(得分: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