在windows phone中相当于IOS方法,称为loadHTMLString:baseURL或android loadDatawithBaseUrl (here)。我想在网站上运行脚本,这就是为什么我需要这个基础网址被调用。
发布于 2015-03-11 06:51:13
通过查看引用链接,我认为您正在尝试实现的是Windows Phone上的web browser
控件,用于在应用程序页面上显示远程HTML页面。
从远程URL加载
第1步:从page.xaml上的工具箱在应用程序页面上加载WebBrowser控件
<Grid x:Name="ContentGrid" Grid.Row="1">
<phone:WebBrowser HorizontalAlignment="Left" Margin="0,0,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="800" Width="470" />
</Grid>
第2步:在page.xaml.cs上编写C#代码(甚至可以使用VB.NET
webBrowser1.Source = new Uri("http://www.foo.com", UriKind.Absolute);
从本地HTML字符串加载
这里的步骤1保持不变,只是在本地加载HTML代码:
第2步: page.xaml.cs上的C#代码
String htmlContent = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">
<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\">
<title></title>
</head>
<body id=\"body\">
<!-- The following code will render a clickable image ad in the page -->
<script src=\"http://www.myscript.com/a\"></script>
</body>
</html>";
webBrowser1.NavigateToString(htmlContent); //This renders the HTML string defined above in the webview.
编辑:另外,如果您希望允许在webview中执行脚本,请将webbrowser控件的IsScriptEnabled
属性设置为true
。
webBrowser1.IsScriptEnabled = true;
https://stackoverflow.com/questions/28972477
复制