This is a migrated thread and some comments may be shown as answers.

[Solved] How to scroll to top of editor programatically?

4 Answers 206 Views
Editor
This is a migrated thread and some comments may be shown as answers.
tom
Top achievements
Rank 1
tom asked on 19 Mar 2009, 05:16 AM
How to scroll to top of editor programatically?
I have several long documents. 
After scroll to bottom of first document, I load the second document, the editor position remain at the bottom.
How do I bring it back up to the top?

Thanks. 

4 Answers, 1 is accepted

Sort by
0
tom
Top achievements
Rank 1
answered on 21 Mar 2009, 06:15 AM
Seems to be a very simple task.
Can anybody help me with this?
 
0
Tervel
Telerik team
answered on 23 Mar 2009, 01:54 PM
Hi Tom,

I would suppose that you are loading content in the editor programmatically, e.g. maybe by using editor.set_html()
To scroll back to the top please try the following code:


//Set cursor to the top of the editor 
window.setTimeout(function() 
editor.setFocus(); 
editor.fire("SelectAll"); 
editor.getSelection().collapse(true); 
}, 100); 


Best regards,
Tervel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Murad Ajani
Top achievements
Rank 1
answered on 03 Nov 2009, 04:54 AM
Hi
I have a similar requirement but would need to detect the scroll position.  I am using this control to display Terms & Conditions and the requirement is to force the user to scroll to the bottom of the control.  For a multiline textbox, I had used the below code.  Is there a similar properties with Editor control?

           var txt = document.getElementById("<%=txtScroll.ClientId %>");
           var height = txt.scrollTop;
           txt.scrollTop = txt.scrollHeight;
            if (txt.scrollTop != height){
               txt.scrollTop = height;
               alert("Please read the Service Agreement before Accept");
           }    

Thanks in advance

0
Rumen
Telerik team
answered on 05 Nov 2009, 11:44 AM
Hi Murad,

You can get a reference to the body element of the editor's document using the following code:

var editor = $find("<%=RadEditor1.ClientID%>");
var txt = editor.get_document().body;

Please, try the following solution:

<telerik:RadEditor runat="server" ID="RadEditor1">
    <content>dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />
    dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />dsadadas<br />
    </content>
</telerik:RadEditor>
<input type="button" onclick="DetectScrollPosition();return false;" value="Detect Scroll Position" />
<script type="text/javascript">
function DetectScrollPosition()
{
     var editor = $find("<%=RadEditor1.ClientID%>");
     var txt = editor.get_document().body;
     var height = txt.scrollTop;
     txt.scrollTop = txt.scrollHeight;
     if (txt.scrollTop != height){
        txt.scrollTop = height;
        alert("Please read the Service Agreement before Accept");
     }   
}
</script>

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Editor
Asked by
tom
Top achievements
Rank 1
Answers by
tom
Top achievements
Rank 1
Tervel
Telerik team
Murad Ajani
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or