森欄
2022-10-27 15:21:25
我想在 iframe 的內(nèi)容上而不是在文本框上執(zhí)行這些 JavaScript 富文本函數(shù),但是每次我嘗試恢復(fù) iframe 的內(nèi)容時(shí),它都會(huì)使用 console.log 返回“NULL”。我怎樣才能解決這個(gè)問題,以便更好地在 iframe 的內(nèi)容上執(zhí)行 JavaScript 函數(shù)。
3 回答
慕斯709654
TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊
您將不得不使用 postMessage() 發(fā)布到 iframe https://robertnyman.com/html5/postMessage/postMessage.html
您還需要在 iframe 代碼中偵聽帖子/事件。
回首憶惘然
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

正如您在此處看到的,控制臺(tái)上沒有任何問題。我剛剛通過 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); }
}
添加回答
舉報(bào)
0/150
提交
取消


