【问题标题】:WP8 Webbrowser, stop navigation without killing pageWP8 Webbrowser,停止导航不杀页面
【发布时间】:2013-03-18 02:07:06
【问题描述】:

我有一个使用 Web 浏览器控件来浏览网站的应用程序。当用户单击将他们带出站点的超链接时,我希望能够停止导航。我试过了。

void wgBrowser_Navigating(object sender, NavigatingEventArgs e)
{
        if (!e.Uri.AbsoluteUri.Contains(BASEURL))
        {
            e.cancel = true;

            return;
        }
        progressPB.Visibility = Visibility.Visible;
}

这实际上会停止导航,但它会终止页面,从而导致导航错误消息出现在网络浏览器中。

我尝试了一些方法,包括导航后的 wgBrowser.Goback(),但这不是真正的“返回”,并导致页面重新加载用户之前输入的完全丢失的数据。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 它是如何杀死页面的?用户点击链接时是否正在执行 JS?网页上有 jQuery 吗?

标签: silverlight windows-phone-7 navigation browser windows-phone-8


【解决方案1】:

你试过IsolatedStorageSettings吗?因为使用IsolatedStorageSettings存储页面导航时数据会更好。

例子:

private void tbUserName_SelectionChanged(object sender, RoutedEventArgs e)
{
            if (appSetting2.Contains("MainPage2"))
            {
                appSetting2["MainPage2"] = this.tbUserName.Text;
            }
            else
            {
                appSetting2.Add("MainPage2", this.tbUserName.Text);
            }
}

【讨论】:

    【解决方案2】:

    使用可以通过WebBrowser控件使用InvokeScreipt方法来停止页面导航。

    yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多