我必须使用 iframe 从文本区域显示 html 代码的预览(整个 html 页面当然以 html 标签...等开头)。 它可以在 webkit 浏览器中运行,但不能在 firefox 中运行。
文本区域:
<textarea id="document_token_body">the source code of a html page here</textarea>
预览区域:
<iframe id="result" width="680px" frameborder="0"></iframe>
和 JavaScript 代码:
document.getElementById('result').contentWindow.document.documentElement.innerHTML = document.getElementById('document_token_body').value;
最佳答案
尝试contentDocument
而不是 contentWindow.document
。
在 Firefox 20 中对我有用:http://jsfiddle.net/7vyDa/
关于javascript - html 'inception' 跨浏览器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14870837/