【发布时间】:2016-03-18 04:56:08
【问题描述】:
我的 Windows 10 通用应用程序正在使用一个 webview,它使用 InvokeScript 调用 JS 函数“eval”,同时将一些其他 javascript 注入该函数。但是,当我测试它时,什么也没有发生。调试显示脚本被正确存储并且它正在命中函数,但 webview 似乎根本没有更新。
private void browser1_LoadCompleted_1(object sender, NavigationEventArgs e)
{
try
{
count++;
browser1.InvokeScript("eval", test);
}
catch (Exception E)
{
}
address.Text = browser1.Source.ToString();
}
}
此代码在 Windows Phone 8 及更早版本上运行良好。但是现在用Windows 10 webview,好像没什么效果。这是将我的脚本存储在测试变量中的代码:
private async void ReadFile()
{
string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Script.js"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
fileContent = await sRead.ReadToEndAsync();
test = new string[] { fileContent };
}
我不确定为什么什么也没发生。我已经确认测试变量在调用 InvokeScript 时确实包含脚本。我什至使用不同且更简单的 JS 脚本测试了 InvokeScript,这些脚本在该应用程序的 Windows Phone 8 版本中肯定有效。当调用 JS 函数时,我是否缺少让 webview 更新的东西?
【问题讨论】:
标签: c# windows windows-phone windows-10 windows-10-universal