如何将信息从嵌入式 iframe 发送到我的网站(嵌入 iframe 的位置)

How can I send information from an embeded iframe to my website( where that iframe is embeded on)

我正在编写一个我不想嵌入 iframe 的网站,iframe 是在不同的域/来源上编码的,我不想将字符串发送到我的网站(javascript站点)每次单击按钮时,我都无法使用 sessionstorage 或 localstorrage,因为 iframe 与站点不在同一来源!

更新

我试过使用 postmessage,这种方法对我来说是新的,我已经能够接收从控制台发送的消息,但由于某种原因我无法从 iframe 发送消息,它没有'不起作用,这是需要发送消息的按钮的代码 <img id="play"src="https://image source" alt="play" onclick="window.postMessage('{{YTID}}', '*');" height="100" width="100"> 按钮显示但不会发送。

我认为这与 window 有关,但我不知道接收 window 的正确 DOM 需要是什么。

我用过post留言方式more about that here

在发送端我使用 window.parent.postMessage('Message', '*'); window.parent 指定将消息发送到 iframe 的父级,这是我的网站,在接收端(在我的网站上)我已使用 window.addEventListener("message", function(message){ more code });

这是为我做的,谢谢