Scroll WebHTMLViewer to top

Is there any way to scroll an HTMLViewer to the top programmatically. I would like to do this after resizing the HTMLViewer programmatically. Don’t see anything in the docs that I can use for this purpose.



HTMLViewer1.executeJavaScript("window.scrollTo(0, 0);")

Michel B, Thanks!

I can’t seem to get it to work. I tried the following without doing any resizing…

htmlViewer_Document.executeJavaScript(“window.scrollBy(100, 100);”)

Nothing happens. I have the browser small enought to display the scroll bars

Is there another setting I have to make on the viewer?


OK. Here is code that gets inside the HTMLViewer content :

HTMLViewer1.executeJavaScript("document.getElementById('"+HTMLViewer1.controlID+"').getElementsByTagName('iframe')[0].contentWindow.scrollTo(0, 0);")

HOWEVER, if the page in the WebHTMLViewer is not on the same domain as your app, it will not work, for security reasons. You will get the following error :

Could not execute returned javascript: Blocked a frame with origin "" from accessing a cross-origin frame. Source: document.getElementById('GrxdEByi').getElementsByTagName('iframe')[0].contentWindow.scrollTo(0, 0);

Tried your second suggestion. Did not work for me either. No errors.

Not sure I have it coded correctly. The only thing I changed was the viewer name from HMLViewer1 to the name of my viewer htmlViewer_Document

Maybe I can solve my problem another way. The problem appears to not so much be a position of the vertical scroll bar, but the position of the page within the viewer. After shrinking the size of the viewer by increasing the Top coordinate from 0 to 160, the vertical scroll bar does in fact remain at the 0 position. The content, however, of the viewer, in this case a PDF file, is displayed with the top cut off as if the Top coordinate of the viewer was still at 0. If I move the vertical scroll bar as little as 1 pixel the content will snap down to where it’s supposed to be.


Well it’s a PDF, it’s not a webpage. The PDF is displayed by the PDF renderer.

If that renderer supports Javascript, then it would work - but I think you might be throwing javascript at something that’s not listening.

Indeed, JavaScript is not available for straight PDF.

Another approach would be to place the HTMLViewer, full size, within a WebContainer. Then you can scroll it the way you want with ScrollTo.