2013-10-10 54 views
1

在我的WinRT應用程序中,我有一個包含打開本地html文件的webview的設置的userControl。我用javascript代碼攔截此html文件的鏈接以啓動本機webbrowser。當我這樣做時,本地webbrowser正確顯示鏈接,但我的應用程序崩潰的同時出現'訪問衝突'異常。從應用程序啓動本機webbrowser時出現訪問衝突異常

這裏是我的用戶代碼:

public sealed partial class SimpleSettingsNarrow : UserControl 
{ 
    public SimpleSettingsNarrow() 
    { 
     this.InitializeComponent(); 
    } 

    private void ConditionWB_Loaded_1(object sender, RoutedEventArgs e) 
    { 
     ConditionWB.ScriptNotify += ConditionWB_ScriptNotify; 
     ConditionWB.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri; 
     ConditionWB.Navigate(new Uri("ms-appx-web:///Assets/testWebview.html")); 
    } 
    private async void ConditionWB_ScriptNotify(object sender, NotifyEventArgs e) 
    { 
     await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Value)); 
    } 

} 

這裏是XAML代碼:

<UserControl 
x:Class="MyNameSpace.SimpleSettingsNarrow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:MyNameSpace" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="768" 
d:DesignWidth="692"> 
<UserControl.Resources> 

</UserControl.Resources> 
<Border BorderBrush="Black" BorderThickness="1,0,0,0"> 
    <Grid Background="White" VerticalAlignment="Stretch"> 
     <!-- Root grid definition --> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="80" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 

     <!-- Header area for panel --> 
     <Grid Background="White" Grid.Row="0"> 

      <Grid Margin="40,32,17,13"> 

       <Grid.Transitions> 
        <TransitionCollection> 
         <EntranceThemeTransition FromHorizontalOffset="50" /> 
        </TransitionCollection> 
       </Grid.Transitions> 

       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="30" /> 
        <ColumnDefinition Width="Auto" /> 
        <ColumnDefinition /> 
       </Grid.ColumnDefinitions> 

       <TextBlock Margin="10,0,0,0" Grid.Column="1" FontFamily="Segoe UI" FontWeight="Normal" FontSize="24.6667" Text="Déclaration de confidentialité" Foreground="Black" TextWrapping="Wrap" HorizontalAlignment="Left" /> 



      </Grid> 
     </Grid> 
     <ScrollViewer Grid.Row="1" Margin="20,20,0,20" Padding="0,0,20,0"> 
      <WebView x:Name="ConditionWB" Loaded="ConditionWB_Loaded_1"></WebView> 

     </ScrollViewer> 


    </Grid> 
</Border> 
</UserControl> 

而且testWebview.html文件包含:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
</head> 
<body> 
test 
<a href="javascript:window.external.notify('http://www.google.fr')">google</a> 


</body> 
</html> 

你有任何想法,爲什麼它崩潰像這樣?

非常感謝。

回答

0

您必須使用Windows 8.1。

在Windows 8.1中,不允許使用AllowedScriptNotifyUris用法,而是在項目「Package.appxmanifest」的「Content URIs」中輸入URL。

注意:給出的URL必須是「https」(http將不起作用)。