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

How to get the whole html from RadEditor

3 Answers 781 Views
Editor
This is a migrated thread and some comments may be shown as answers.
raymond zhou
Top achievements
Rank 1
raymond zhou asked on 25 Feb 2011, 10:39 PM
We ran into a situation that we need get/set the whole html from radeditor, but GetHtml()/SetHtml() only get/set the content whithin <body> tag.

what happens is:
on server side, we use
radeditor.html = "<html><header>...</header><body>...</body></html>"

on client side, we need to get the html, do some process and set it back. But GetHtml() only get the content whithin <body>, and SetHtml does the same.

var e1 = <%=radEditor.ClientID%>;
  
var h1 = e1.GetHtml();
process h1...
  
e1.SetHtml(h1);

On server side, we can do that with html property. But how can I update the whole html from client side? 

Thanks

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 01 Mar 2011, 12:05 PM
Hello Raymond,

Here is an example how to obtain the FULL HTML content from RadEditor Classic:

<radE:RadEditor ID="radeditor" runat="server" EnableDocking="false"></radE:RadEditor>
<input type="button" value="Show HTML" onclick="ShowFullHTMLContent();return false;" />
 
    <script type="text/javascript">
    function ShowFullHTMLContent() {
        var editor = GetRadEditor ("<%=radeditor.ClientID%>");
        //to get formatted html code (looks cleaner and is lowercase, therefore xhtml compliant)
        //if this is of no concern you can remove the mode changes
        editor.SetMode(2);
        //the correct method to get the html content
        var someContent = editor.GetHtml(true);
        alert(someContent);
        //return to design mode. There could be a flicker for the user, though
        editor.SetMode(1);
        //the editor adds the content just before the </body> tag as I am not implementing any logic in the editing process
        //and content cannot exist after the </html> tag
        //You can see the initial position if you do not set the mode back to design
        someContent += "more content";
        //set the content back in the editor
        editor.SetHtml(someContent);
    }
</script>

You need to switch to HTML mode to obtain the full HTML content, because it is not possible to edit full HTML content in editable DIV / IFRAME elements.


Kind regards,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Pruthvi
Top achievements
Rank 1
answered on 07 Oct 2020, 12:30 PM

Hi, We need help here. I want to call this var editor = $find("<%=editor1.ClientID %>"); from .JS file instead of .aspx file. But when I am calling $find method from function which reside in .JS file, getting "$find is not defined" error.

Please advice hoe to fix this.

0
Peter Milchev
Telerik team
answered on 08 Oct 2020, 12:05 PM

Hello Pruthvi,

The <%=editor1.ClientID %> is a server tag so you cannot use it in an external JS file. Instead, you can either set the id as a global variable or use one of the other approaches to obtain a client-side reference.

For example, setting a custom CssClass to the Editor and then use it as explained below:

Another specific about the scripts is that $find is a MSAJAX method loaded with its scripts, meaning you need to have the script loaded in order to have access to $find, i.e. you need to load your script under the script manager or call the function that uses $find after the Sys.Application.Load event:

The same is applied to the client-side object of IScriptControl instances such as the Telerik controls. The client-side objects of the controls are most of the times not accessible on document.ready.

That is why if you are accessing such a control, you should either use the control's OnClientLoad client-side event or a global Sys.Application.add_load() handler:

function pageLoadHandler() {
    // you can access client-side objects now via $find()


    // Sys.Application.remove_load(pageLoadHandler);  
}
Sys.Application.add_load(pageLoadHandler); 

Regards,
Peter Milchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Editor
Asked by
raymond zhou
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Pruthvi
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or