htmlviewer in webapp

webapp…

anyone know how to disable the vertical scrollbar in the htmlviewer ?
(if user scrolls then hits print, the top of the document is missing from the print)
thanks

Hiding the scrollbars is not simple, if you want to support all browsers.

See http://stackoverflow.com/questions/3296644/hiding-the-scrollbar-on-an-html-page#13184693

Another way would be to scroll the HTMLViewer back to 0, with JavaScript SccrollTo
https://www.w3schools.com/jsref/met_win_scrollto.asp

almost there … what did I do wrong?

ExecuteJavaScript “htmlviewer1.scrollTo(0, 0);”

In most cases we will never know unless you tell us what happened with what you tried (errors and results and such.)

However, this one stands out. On the Web framework, the controls on the page in the browser don’t end up with the names you give them in the IDE. This Javascript that may work (or at least lead you in the right direction):

ExecuteJavascript("document.getElementById('" + htmlviewer1.ControlID + "').scrollTo(0, 0);")

I don’t know off the top of my head if html viewer iFrames have an _inner component or not. If it does, you will need to adjust the getElementById to find the correct element.

[quote=322965:@Gary Dalal]almost there … what did I do wrong?

ExecuteJavaScript “htmlviewer1.scrollTo(0, 0);”[/quote]

You should look at the structure of the HTMLViewer, using the browser developer tools.

WebHTMLViewer is made of an iframe within a div.

Try

ExecuteJavascript("document.getElementById('" + htmlviewer1.ControlID + "').getElementsByTagName('iframe')[0].scrollTo(0, 0);")

aha - interesting reading gentlemen… I tried both codes in a button, but I’m getting
“scrollTo is not a function” with both

http://stackoverflow.com/a/1229879
It looks like you need to access the content of the iframe, not just the iframe itself.
Add .contentWindow between the [0] and .scrollTo in Michel’s code.

The working code is :

self.ExecuteJavascript("document.getElementById('" + htmlviewer1.ControlID + "').getElementsByTagName('iframe')[0].contentDocument.scrollTo(0, 0);")

Note, and that is mighty important, it will work only for code on the same server as your app. If you try to use this code when the WebHTMLViewer is on another site, you will get a JavaScript security exception.

Awesome - thanks guys. I had no idea it would be that complex. Learning a lot…