Detect scroll to bottom in WebBrowser control

﹥>﹥吖頭↗ 提交于 2019-12-04 18:34:27

You should handle onscroll event of window object and check if scrollHeight - scrollTop equals to clientHeight for documentElement. To do so:

private void webBrowser1_DocumentCompleted(object sender, 
    WebBrowserDocumentCompletedEventArgs e)
{
    this.webBrowser1.Document.Window.AttachEventHandler("onscroll", OnScroll);
}

void OnScroll(object sender, EventArgs e)
{
    var script =
    @"(function()
       {
           var e = document.documentElement;
           if (e.scrollHeight - e.scrollTop === e.clientHeight)
               return true;
           else
               return false;
       })();";
    var result = webBrowser1.Document.InvokeScript("eval", new object[] { script });
    if ((bool)result)
        MessageBox.Show("Scrolled to end!");
}

The scrollbar is not part of the WebBrowser control, but of the Html displayed. You have to subscribe to the Scroll event of the Window of the displayed Document

webBrowser1.Document.Window.Scroll += MyScrollCode;

https://msdn.microsoft.com/en-us/library/system.windows.forms.htmlwindow.scroll(v=vs.110).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!