Resolve CKEditor 4.5.4 Editor does not display HTML entities, automatically filtering HTML problems

Source: Internet
Author: User

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}--> ']

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.