Hello,
I've been trying to create button (Toolbar button for HTML5) that will scroll to the top of the page when pressed. It is very useful to me since we have long articles in our knowledge base. I have tried the Javascript way, with window.scrollTo(0,0) but no effect. I think because the actual page is not scrolling.
Do you have any idea on how to create this functionality?
Go to Top button
Re: Go to Top button
Using window.scrollTo(0,0); will scroll the current page, so it will work if it's in the body of the topic itself; e.g.
However, the toolbar is not part of the topic page in either WebHelp or HTML5 help, it is in a separate page which is inside an iframe/frame. So that script won't work since it will try to scroll the page that contains the toolbar, not the page containing the topic.
To get this to work in a toolbar button, you need to tell it to scroll the page iframe/frame that contains the topic.
For HTML5, you need to scroll the 'topic' iframe:
For WebHelp you need to scroll the 'body' frame:
Code: Select all
<a href="#" onclick="javascript:window.scrollTo(0,0);">Go to top</a>To get this to work in a toolbar button, you need to tell it to scroll the page iframe/frame that contains the topic.
For HTML5, you need to scroll the 'topic' iframe:
Code: Select all
window.top.topic.scrollTo(0,0);Code: Select all
window.top.body.scrollTo(0,0);Re: Go to Top button
Thank you very much! I totally forgot about the topic iframe. 