我想在 iframe 的内容上而不是在文本框上执行这些 JavaScript 富文本函数,但是每次我尝试恢复 iframe 的内容时,它都会使用 console.log 返回“NULL”。我怎样才能解决这个问题,以便更好地在 iframe 的内容上执行 JavaScript 函数。
3 回答

慕斯709654
TA贡献1840条经验 获得超5个赞
您将不得不使用 postMessage() 发布到 iframe https://robertnyman.com/html5/postMessage/postMessage.html
您还需要在 iframe 代码中侦听帖子/事件。

回首忆惘然
TA贡献1847条经验 获得超11个赞
正如您在此处看到的,控制台上没有任何问题。我刚刚通过 xampp 打开了您的 html。所以它打开了localhost。我正在使用 xampp。
// that console comes from here..
function initDoc() {
oFrame = document.getElementById("myiframe");
oDoc = oFrame.contentDocument;
console.log(oDoc);
sDefTxt = oDoc.innerHTML;
if (document.compForm.switchMode.checked) { setDocMode(true); }
}
添加回答
举报
0/150
提交
取消