iframe:如何显示原始(纯文本)html? [英] iframe: How to display raw (plain text) html?
本文介绍了iframe:如何显示原始(纯文本)html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在IFRAME中将HTML字符串显示为原始/纯文本HTML。
例如,显示";<b>Hello World</b>
";(而不是Hello World)。
我已尝试这样显示它:
<iframe srcdoc="<pre><b>Hello World</b></pre>"></iframe>
但是它没有起作用。它显示粗体";Hello world&qot;文本。
我正在使用Nuxt.js。
我错过了什么?
推荐答案
无iFrame
<pre id="code"></pre>
<script>
document.getElementById('code').textContent = '<b>Hello World</b>';
</script>
使用IFRAME
<iframe id="codeFrame"></iframe>
<script>
function writeToIframe(iframe, markup) {
iframe.contentWindow.document.open();
iframe.contentWindow.document.write('<pre id="code"></pre>');
iframe.contentWindow.document.getElementById('code').textContent = markup;
iframe.contentWindow.document.close();
}
writeToIframe(document.getElementById('codeFrame'), '<b>Hello World</b>');
</script>
这篇关于iframe:如何显示原始(纯文本)html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文