如何在UWP中获得WebView上的scrollYOffset?
我在VisualStudio上尝试了这段代码。但它变成了: System.Exception:“来自HRESULT:0x80020101的异常” 我如何解决它如何在UWP中获得WebView上的scrollYOffset?,webview,uwp,scrolltop,Webview,Uwp,Scrolltop,我在VisualStudio上尝试了这段代码。但它变成了: System.Exception:“来自HRESULT:0x80020101的异常” 我如何解决它 string function = @"window.external.notify(document.body.scrollTop)"; await PinView.InvokeScriptAsync("eval", new string[] { function }); System.Exception:“来自HRESULT:0x
string function = @"window.external.notify(document.body.scrollTop)";
await PinView.InvokeScriptAsync("eval", new string[] { function });
System.Exception:“来自HRESULT:0x80020101的异常”
web视图内容中的脚本可以使用window.external.notify和字符串参数将信息发送回应用程序。但是,document.body.scrollTop的类型是number。因此,您应该将参数转换为字符串
string function = @"window.external.notify(document.body.scrollTop.toString())";
await MyWebView.InvokeScriptAsync("eval", new string[] { function});
要接收这些消息,请处理ScriptNotify事件
private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
MyText.Text = e.Value.ToString();
}
谢谢我理解。我试过这根绳子。但仍向系统发出警报。异常:“来自HRESULT的异常:0x80020101”。我不知道为什么?字符串函数=@window.external.notifydocument.documentElement.scrollTop.toString;我也错了。非常感谢!我解决了这个问题。在呈现页面之前,运行脚本会出错。完成后脚本运行良好。