javascript - 无法使用javaScript在HTML中打印特定字符串

标签 javascript html error-handling xss

我面临使用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/

相关文章:

python - PySide 程序崩溃处理程序

python - 如何处理 scipy 中的这个 AttributeError?这很奇怪

javascript - three.js transformControls位置错误

javascript - 从树形结构数据库生成 JSON

javascript - 在javascript中使用正则表达式和replace()替换数组元素

javascript - 从客户端提供的时间戳(和时区)获取正确的时间

javascript - 将组件传递给 Angularjs 对话框模板时删除额外的 md-dialog 包装器

html - 盒子阴影底部像括号

html - 浏览器覆盖了我的 CSS 字体

C#:如何构造这个要被覆盖的方法