How to add CSS or JS code in the editor

Source: Internet
Author: User
Tags cdata

Recently in the use of WordPress to make a website project, you need to add custom JS script and CSS in the background editor
After adding it in the editor, Found in the browser JS script to execute the problem and the CSS script directly by the WordPress saved by the time filtered out after the discovery of the reason is the WordPress default TINYMCE when switching from code mode to visual mode when the script is processed more shameless is the CSS script is deleted directly
 
   
  
  1. //编辑器里代码模式下的代码
  2. <script type="text/javascript">
  3. //my code....
  4. </script>
  5. //编辑器里可视化模式下的代码
  6. <script type="text/javascript">
  7. // <![CDATA[
  8. //my code....
  9. // ]]>
  10. </script>
Description on Wiki CDATA

CDATA Sections in xhtml documents is liable to being parsed differently by web browsers if they render the docu ment as HTML, since HTML parsers don't recognise the CDATA start and end markers, nor do they recognise HTML entity refer Ences such as &lt; Within <script> tags. This can cause rendering problems in web browsers and can leads To cross-site scripting vulnerabilities if used t o Display data from untrusted sources, since the kinds of parser would disagree on where the CDATA section ends.

Since it is useful to being able to use Less-than signs (<) and ampersands (&) in Web page scripts, and to a lesser ex Tent styles, without have to remember to escape them, it's common to use CDATA markers around the text of inline <SC Ript> and <style> elements in XHTML documents. But so, the document can also is parsed by HTML parsers, which does not recognise the CDATA markers, the CDATA markers A Re usually commented-out, as in this JavaScript example:


So the correct way of writing it should be like this
  
 
  1. //JavaScript example:
  2. <script type="text/javascript">
  3. //<![CDATA[
  4. //mycode
  5. document.write("<");
  6. //]]>
  7. </script>

  8. //CSS example:
  9. <style type="text/css">
  10. /*<![CDATA[*/
  11. //my code
  12. body { background-image: url("marble.png?width=300&height=300") }
  13. /*]]>*/
  14. </style>

 Reference: JavaScript <! [cdata[Web Standard usage methods Some Web site source script written in the <![ Cdata[...] What does > do for you?
Wiki cdatawhat is CDATA in HTML?


From for notes (Wiz)

How to add CSS or JS code in the editor

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.