我正在开发Windows Phone PhoneGap应用。我可以知道如何获取PhoneGap的webview的当前URL吗?
答案 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);
}