Set the HTML content of an instance's <body>
element with editor.content.set()
.
Example
// Set the HTML content of an instance var contentToSet = "<p>Any HTML Content</p>"; editor.content.set(contentToSet);
Parameters
html | String | Specify the HTML to which the editor’s contents will be set as a string. |
Returns
No return value.
Injecting Content into JavaScript
If you are using a server side programming language to inject your content you need to make sure that the result of your code creates valid JavaScript. For example, if you use this in a JSP:
var content = "${myObject.content}";
you will create invalid JavaScript if ${myObject.content} contains any double quotes and/or carriage returns and/or line feeds. If ${myObject.content} had a double quote you would end up with this:
var content = "<p>This is content with "quoted content" in the paragraph</p>";
As you can see the double quotes in the content leads to a malformed string. CR/LF characters will create similar issues as the string would stretch over multiple lines. To avoid these issues you should remove CR and LF characters and escape any other characters that could cause issues for a string. These include:
- Single quote
- Double quote
How you escape these characters is specific to the server side language you are using but all popular server side languages provide the ability to escape characters in strings.