如何在 UWP 中的 WebView 上获取 scrollYOffset?
How to get scrollYOffset on WebView in UWP?
我在 Visual studio 上试过这段代码。但它变成了:
System.Exception: 'Exception from HRESULT: 0x80020101'
我该如何解决?
string function = @"window.external.notify(document.body.scrollTop)";
await PinView.InvokeScriptAsync("eval", new string[] { function });
System.Exception: 'Exception from HRESULT: 0x80020101'
Web 视图内容中的脚本可以使用 window.external.notify 和 string
参数将信息发送回您的应用程序。但是,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();
}
我在 Visual studio 上试过这段代码。但它变成了:
System.Exception: 'Exception from HRESULT: 0x80020101'
我该如何解决?
string function = @"window.external.notify(document.body.scrollTop)";
await PinView.InvokeScriptAsync("eval", new string[] { function });
System.Exception: 'Exception from HRESULT: 0x80020101'
Web 视图内容中的脚本可以使用 window.external.notify 和 string
参数将信息发送回您的应用程序。但是,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();
}