CKEditor 4.5.4, when editing, using source edit, when the content contains JavaScript, style tags, the database has JavaScript, style tags, input to the page can also be executed, but I edited the time is gone, It is ckeditor to filter them out, you need to do the following configuration:
The code is as follows |
Copy Code |
Ckeditor.replace (' textarea_id ', {allowedcontent:true});
|
Finally, a problem was found:
After {allowedcontent:true} is set, HTML entities are rendered as true HTML effects, although HTML is not filtered.
That is, I wanted to just show the HTML code, rather than let it render the actual HTML effect.
Fortunately CKEditor provides the JS operation CKEditor instance, assigns the editor the value the interface SetData (' editor's default value ').
The original front-end code reference is as follows:
The code is as follows |
Copy Code |
<textarea id= "<!--{$inputId}-->" name= "<!--{$inputName}-->" ><!--{$defaultValue}--></ Textarea> <script type= "Text/javascript" > var ck_obj_<!--{$inputId}--> = Ckeditor.replace (' <!--{$inputId}--> ', {width: ' <!--{$width}--> ') Height: ' <!--{$height}--> '}); </script> |
After the transformation of the front-end Code reference is as follows:
The code is as follows |
Copy Code |
<pre id= "pre_<!--{$inputId}-->" class= "hidden" > <!--{$defaultValue}--> </pre> <textarea id= "<!--{$inputId}-->" name= "<!--{$inputName}-->" ></textarea> <script type= "Text/javascript" > var ck_obj_<!--{$inputId}--> = Ckeditor.replace (' <!--{$inputId}--> ', {width: ' <!--{$width}--> ') Height: ' <!--{$height}--> '}); ck_obj_<!--{$inputId}-->.setdata ($ (' #pre_ <!--{$inputId}--> '). html ()); $ (' #pre_ <!--{$inputId}--> '). Remove (); </script> |
Note that the server-side PHP Gets the contents of the editor, the reference code is as follows:
code is as follows |
copy code |
$_post[' <!--{$inputName}--> '] |