【发布时间】:2014-02-20 22:09:42
【问题描述】:
我正在开发一个 Windows Phone 8 应用程序,我是 Windows Phone 8 的新手。
我正在使用 WebBrowser Control 并尝试加载具有 javascript 的 html 页面。
在 button_Click 事件中我调用 Webbrowser.InvokeScript("JavascriptFunctionName"),但它总是抛出错误:80020006,即使 WebBrowser.isScriptEnabled = true。
下面是代码
Html 页面:MyHtmlPage.html
<!DOCTYPE html>
<html>
<head title="test">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
#map-canvas {
height: 100%;
}
</style>
<script type="text/javascript">
function initialize() {
var helloText = document.getElementById("Hello");
helloText.textContent = "Initialized";
return ("Initialize");
}
</script>
</head>
<body>
<div id="test-canvas" />
<label id="Hello">Hello</label>
</body>
</html>
Cs 文件:MainPage.cs
private string TestUri = @"Html/Test.html";
private string stringHtml = string.Empty;
public MainPage()
{
InitializeComponent();
WebBrowser.IsScriptEnabled = true;
WebBrowser.IsGeolocationEnabled = true;
}
private void WebBrowser_Loaded(object sender, RoutedEventArgs e)
{
var resource = App.GetResourceStream(new Uri(TestUri, UriKind.Relative));
stringHtml = new StreamReader(resource.Stream).ReadToEnd();
WebBrowser.NavigateToString(stringHtml);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
//Error
string returnValue = WebBrowser.InvokeScript("initialize");
}
catch(Exception ex)
{
}
}
帮帮我.. 谢谢。
【问题讨论】:
-
@UweKeim,不是这样。我们确定
<script>s根本没有在 OP 的情况下运行,尽管目前尚不清楚原因。
标签: c# javascript windows-phone-8 webbrowser-control