从 iframe javascript 将 Cookie 设置为父窗口

Onl*_*ine 5 javascript cookies iframe

请任何人帮助我从 javascript 中的 iframe 在父窗口上设置 cookie。如果可以的话,请提供一些相关的链接。例如:父页面有域ABC.com

该页面上的 IFRAME 指向XYZ.com,我想在 iframe 中编写一个脚本,以在 ABC.com(位于父页面上)上放置一个 cookie。

小智 3

您可以使用 postMessage 从子窗口(即 iFrame)发布消息,然后在父窗口监听事件。

  window.parent.postMessage("Value", "*");
  window.addEventListener();
Run Code Online (Sandbox Code Playgroud)

这篇文章可能会帮助您了解更多。 如何跨域使用window.postMessage?