简体   繁体   中英

Current URL of the webview in Windows Phone PhoneGap app

I am developing Windows Phone PhoneGap app. May I know how to get the current URL of the webview of the PhoneGap?

I achieved the objective by handling the event through this.CordovaView.Browser.Navigated += Browser_Navigated; where Browser_Navigated function is as follows.

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);
        }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM