在Web浏览器中向下滚动页面

时间:2014-07-22 11:10:26

标签: c# winforms browser webbrowser-control

我的Windows窗体中有一个Web浏览器,我想让它自动向下滚动页面。现在我这样做

this.webBrowser.Document.Window.ScrollTo(0, int.MaxValue);

但是当我开始申请时,webBrowser不会滚动。为什么呢?

3 个答案:

答案 0 :(得分:1)

这将有效!!!)))

class KeyHandle
{
    private static Int32 WM_KEYDOWN = 0x100;
    private static Int32 WM_KEYUP = 0x101;

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true)]
    static extern bool PostMessage(IntPtr hWnd, int Msg, System.Windows.Forms.Keys wParam, int lParam);

    public static void SendKey(IntPtr hWnd, System.Windows.Forms.Keys key)
    {
        PostMessage(hWnd, WM_KEYDOWN, key, 0);
    }
}

通话方式:

KeyHandle.SendKey(this.webBrowser.Handle, Keys.PageDown);

答案 1 :(得分:0)

脚本:

function top() {
    document.getElementById( 'top' ).scrollIntoView();    
};

function bottom() {
    document.getElementById( 'bottom' ).scrollIntoView();
    window.setTimeout( function () { top(); }, 2000 );
};

bottom();

HTML:

<div id="top">top</div>
<div id="bottom">bottom</div>

答案 2 :(得分:0)

$(document).ready(function () {
    var myInterval = false;
    myInterval = setInterval(AutoScroll, 2000);

    function AutoScroll() {
        var iScroll = $(window).scrollTop();
        iScroll = iScroll + 500;
        $('html, body').animate({
            scrollTop: iScroll
        }, 1000);
    }

    $(window).scroll(function () {
        var iScroll = $(window).scrollTop();
        if (iScroll == 0) {
            myInterval = setInterval(AutoScroll, 2000);
        }
        if (iScroll + $(window).height() == $(document).height()) {
            clearInterval(myInterval);
        }
    });
});