Is there a javascript function that recognize if a string variable contains HTML code?
I would like to avoid this case because if I use innerHTML and the user has submitted something like <img src='link'> it doesn’t appear the string but the real image…
I hope I explained
Thank you!
Is there a javascript function that recognize if a string variable contains HTML code?
Share
You can just replace 3 very special characters:
&: used for glyph notation<: opening bracket for html tags>: closeing bracket for html tagsI did a little magic so \r\n becomes a newline, and
<br>tags are preserved