取消/停止WebView导航

时间:2013-06-08 20:19:28

标签: c# windows-8

如何在导航(网址)下载网页浏览中的html内容时停止导航?我试过这个

 private void btnCancel_Click(object sender, RoutedEventArgs e)
 {
     WebView1.LoadCompleted -= new Windows.UI.Xaml.Navigation.LoadCompletedEventHandler(load_Completed);               
 }

 private void load_Completed(object sender, NavigationEventArgs e)
 {
     //some code after the content is loaded  
 }

但导航过程不会停止......

1 个答案:

答案 0 :(得分:0)

我不确定你使用什么样的WebView,但可能你可以这样做:

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
     try
     {
         string[] args = { "history.go(-1);" };
         WebView1.InvokeScript("eval", args);
     }
     catch {}
 }