What exactly do I have to escape inside a `script` element?

后端 未结 3 1368
轻奢々
轻奢々 2020-12-16 00:28

What parts of JavaScript code do I have to escape inside a script element in a HTML page? Is <>& enough or too much?

[EDI

3条回答
  •  盖世英雄少女心
    2020-12-16 01:26

    Escaped <, > and & does not work with many browsers. It is good an enough if you put everything inside a CDATA section. Please note that the CDATA section itself will have to be in a JavaScript comment, for this to work with all browsers.

    
    

提交回复
热议问题