在Windows窗体应用程序中使用以下代码在Web浏览器中滚动页面:
HtmlDocument doc = webBrowser.Document;
mshtml.IHTMLDocument2 htmldoc = (mshtml.IHTMLDocument2)doc.DomDocument;
htmldoc.parentWindow.scrollBy(265, 20);
有没有人知道如何在WPF应用程序中执行相同操作(不使用WindowsFormsHost)?
答案 0 :(得分:4)
如果您正在使用System.Windows.Controls.WebBrowser课程,请查看Document媒体资源。您应该能够将其强制转换为mshtml.HTMLDocument或mshtml.IHTMLDocument2和代码
mshtml.HTMLDocument htmlDoc = webBrowser.Document as mshtml.HTMLDocument;
if (htmlDoc != null) htmlDoc.parentWindow.scrollBy(265, 20);
应该适合你。
希望这有帮助,尊重
答案 1 :(得分:1)
你应该轻松地做到:
private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
((WebBrowser)sender).InvokeScript("eval", "$( document ).scrollTop( 1700 );");
}
答案 2 :(得分:0)
Javascript:
的window.onload = toBottom;
function toBottom(){alert("滚动到底部......"); window.scrollTo(0,document.body.scrollHeight); }
HTML:
> <html>
> <head>
> <script src="testme.js" language="javascript" type="text/javascript"></script>
> </head>
> <body>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> Some big text<br>
> </body>
> </html>