我面临使用javaScript将此字符串呈现为html的困难
"<img onerror='window.document.body.innerHTML = \"<h1>XSS</h1>\";' src=''> "
当我尝试使用JavaScript将其呈现为HTML元素时,我得到的唯一输出是在纯页上的 XSS
请提出一种我可以将其呈现为纯文本格式的html的方法。
最佳答案
尝试使用Node.textContent
代替Node.innerHTML:
"<img onerror='window.document.body.textContent = \"<h1>XSS</h1>\";' src=''> "
https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#Differences_from_innerHTML
关于javascript - 无法使用javaScript在HTML中打印特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52010950/