How to Scroll a WPF WebBrowser programmatically?
In Windows Forms Applications Im using the following Code to scroll the Page inside a Webbrowser:
HtmlDocument doc = webBrowser.Document;
mshtml.IHTMLDocument2 htmldoc = (mshtml.IHTMLDocument2)doc.DomDocument;
htmldoc.parentWindow.scrollBy(265, 20);
开发者_Go百科
Does anyone know how to do the same in an WPF Application (without using WindowsFormsHost)?
If you're using System.Windows.Controls.WebBrowser class take a look at the Document property. You should be able to cast it to mshtml.HTMLDocument or mshtml.IHTMLDocument2 and code
mshtml.HTMLDocument htmlDoc = webBrowser.Document as mshtml.HTMLDocument;
if (htmlDoc != null) htmlDoc.parentWindow.scrollBy(265, 20);
should be working fine for you.
hope this helps, regards
you should do it easily :
private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
((WebBrowser)sender).InvokeScript("eval", "$( document ).scrollTop( 1700 );");
}
The Javascript:
window.onload=toBottom;
function toBottom() { alert("Scrolling to bottom ..."); window.scrollTo(0, document.body.scrollHeight); }
The 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>
精彩评论