使用 Javascript 将消息从页面传递到父框架,而不使用 HTML 5

发布于 2024-12-22 18:26:56 字数 406 浏览 4 评论 0原文

我有以下场景,其中有一个页面“parentPage.html”,其中包含一个 iFrame“parentFrame”,该 iFrame 托管页面“childFrame.html”。 “childFrame.html”包含另一个名为“childFrame”的框架,并将该页面称为“sample.html”。现在,我想从“sample.html”发送消息并在“parentPage.html”或“c​​hildFrame.html”接收它。

我尝试使用 Porthole 库。然而,它并不能帮助我解决这个特定的场景。另请注意,上述页面不必位于同一域中。

如果您能让我知道如何解决这个特定问题,那就太好了。

提前致谢。

I have the following scenario where I have a page say “parentPage.html”, which contains an iFrame say “parentFrame” which hosts the page “childFrame.html”. “childFrame.html” contains another frame called “childFrame” and calls the page “sample.html”. Now, I want to send a message from “sample.html” and receive it at “parentPage.html” or “childFrame.html”.

I've tried using the Porthole library. However, it doesn't help me in solving this particular scenario. Also, please note that the above mentioned pages need no be in the same domain.

It would be great if you could let me know on how I can solve this particular problem.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福还没到 2024-12-29 18:26:56

有一种解决方法,称为跨框架技术,请参阅链接以了解此技术 http://www.julienlecomte.net/blog/2007/11/31/

There is a work around for this which is called crossframe technique please see the link to understand this technique http://www.julienlecomte.net/blog/2007/11/31/

忆梦 2024-12-29 18:26:56

尝试按照 example.html 中的流程运行 JavaScript:

top.window.myVar = "my message content"; // parentPage.html will receive the message

或者

parent.window.myVar = "my message"; // childFrame.html should receive the message

,您也可以调用父框架或顶部框架中的函数。

Try run JavaScript as flows in example.html:

top.window.myVar = "my message content"; // parentPage.html will receive the message

or

parent.window.myVar = "my message"; // childFrame.html should receive the message

also, you can call functions in parent frame or top frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文