Escape </ in script tag contents

后端 未结 4 1230
死守一世寂寞
死守一世寂寞 2021-01-01 19:26

In HTML, tags and entities aren\'t parsed within

4条回答
  •  情歌与酒
    2021-01-01 20:01

    I came here looking for a way to universally escape inside the JavaScript code.

    After bit of research I figured that if you are trying to escape in JavaScript code so it can be safely embedded in html between tags you should replace with or . It's safer to do because if you replace it with <\/script you might break JavaScript code like this: var q = -1

    Be careful not to look for but rather because will end your script just as well as does.

    Sorry, it doesn't help OP in any way. Accepted answer is absolutely correct that you need to know what constructs are legal in language you have inside your to know how to escape occurrence without braking the code.

提交回复
热议问题