森欄
2022-10-27 15:21:25
我想在 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
提交
取消