Detect scroll to bottom in WebBrowser control

I am creating a Windows Form to accept some terms and conditions for a company. So the terms and conditions are on the web and it is navigated to the WinForm through WebBrowser control. It is required to enable the Accept button only after the full document is scrolled to the bottom. I am searching for an Event similar to ValueChanged Event in VScrollBar control(mentioned below) or any other option.

private void vScrollBar1_ValueChanged(object sender, EventArgs e)
        if (vScrollBar1.Value+9 == vScrollBar1.Maximum)
            acceptBtn.Enabled = true;



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 =
           var e = document.documentElement;
           if (e.scrollHeight - e.scrollTop === e.clientHeight)
               return true;
               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;


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.