Tarou
Tarou

Reputation: 57

How to get scrollYOffset on WebView in UWP?

I tried this code on Visual studio. But it becomes :

System.Exception: 'Exception from HRESULT: 0x80020101'

How can I resolve it?

string function = @"window.external.notify(document.body.scrollTop)";

await PinView.InvokeScriptAsync("eval", new string[] { function });

Upvotes: 0

Views: 265

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32785

System.Exception: 'Exception from HRESULT: 0x80020101'

Scripts in the web view content can use window.external.notify with a string parameter to send information back to your app. However, the type of document.body.scrollTop is number. So, you should convert the parameter to string.

string function = @"window.external.notify(document.body.scrollTop.toString())";
await MyWebView.InvokeScriptAsync("eval", new string[] { function});

To receive these messages, handle the ScriptNotify event.

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    MyText.Text = e.Value.ToString();
}

Upvotes: 1

Related Questions