javascript - 如何在没有查询字符串的情况下将信息从父窗口传递到子窗口? [英] How to pass information from parent window to child window without query string in JavaScript?

查看:18
本文介绍了javascript - 如何在没有查询字符串的情况下将信息从父窗口传递到子窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将信息从父窗口传递到子窗口,但不能使用查询字符串,因为信息太多并且弹出窗口被阻止.他们有不同的域.(跨域)我将如何实现这一目标?我希望在子窗口打开(加载 JavaScript)后立即传递信息

I am looking to pass information from a parent window to a child window, but cannot use a query string because there is too much information and the pop-up gets blocked. They have different domains. (cross-origin) How would I achieve this? I want the information to be passed as soon as the child window is open (the JavaScript is loaded)

推荐答案

发布一条我准备好了"的消息应该可以.

Posting an "I am ready" message should work.

家长:

var child = window.open(childURL);
window.addEventListener("message",(e)=>{
    if(e.data == "ready")
    {
        e.source.postMessage("some data for you","*");
    }
})

孩子:

window.addEventListener("load",()=>{
    window.opener.postMessage("ready","*");
})
window.addEventListener("message",(e)=>{
    console.log(e.data);
});

这篇关于javascript - 如何在没有查询字符串的情况下将信息从父窗口传递到子窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆