我有一个HTML字符串
我想使用JavaScript将其设置为iframe。我试图设置这样的HTML:
contentWindow.document.body.innerHTML
要么
contentDocument.body.innerHTML
要么
document.body.innerHTML
但IE提供“访问被拒绝”。或“对象不支持此属性或方法”。或“操作的最终元素无效”。错误。
这是我的完整代码:
$(document).ready(function(){
var htmlString = "
Hello world";var myIFrame = document.getElementById('iframe1');
// open needed line commentary
//myIFrame.contentWindow.document.body.innerHTML = htmlString;
//myIFrame.contentDocument.body.innerHTML = htmlString;
//myIFrame.document.body.innerHTML = htmlString;
//myIFrame.contentWindow.document.documentElement.innerHTML = htmlString;
});
This is iframe:
Your browser does not support iframes.