我有兩個獨立的網路應用程式,一個有角度的父應用程式和一個反應子應用程式。父應用正在 iframe 中加載子應用。我正在嘗試讓這些應用程式相互交談,window.postMessage()但訊息沒有被正確發送或沒有被接收。
這正是我嘗試過的。
家長應用:
window.postMessage(message, "*")
兒童應用程式:
window.addEventListener("message", (event) => {
console.log(event)
}
我唯一需要做的就是當我控制臺登錄父視窗時,我看到:
postMessage: f postMessage: ()
length: 1
name: "postMessage"
arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not
be accessed on strict mode functions or the arguments objects for calls to
them at Function.s (<anonymous>:1:83)]
caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not
be accessed on strict mode functions or the arguments objects for calls to
them at Function.s (<anonymous>:1:83)]
uj5u.com熱心網友回復:
父級必須從window目標(子行程,在您的情況下為 iframe)而不是從window父級物件發送訊息:
const child = document.querySelector('iframe').contentWindow;
child.postMessage(message, "*")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/459031.html
標籤:javascript 打字稿 dom
