Jar*_*iak 5 webview windows-phone-8 windows-phone-8.1
我试图从webview控件获取DOM模型,或者只是通过XML工具处理它.该控件不提供任何返回我需要的属性.我用JS找到了一个解决方案:
string html = Browser1.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });
Run Code Online (Sandbox Code Playgroud)
但我得到一个未实现的例外.
我究竟做错了什么?我是WP编程的新手.
就像Romasz说的那样使用InvokeScriptAsync - 但要确保首先加载页面.
样品申请:
<Grid>
<StackPanel>
<WebView x:Name="myWebView" Height="300" VerticalAlignment="Top" />
<Button Content="Read HTML" Click="Button_Click" />
<TextBlock x:Name="myTextBlock"></TextBlock>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.myWebView.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
string html = await myWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
myTextBlock.Text = html;
}
catch (Exception ex)
{
}
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
3886 次 |
| 最近记录: |