使用BroadcastChannel跨页签通讯 机智的好青年 2024-01-28 70 阅读1分钟 条件: 同一个域名; // 1新建一个loginEvent频道 const channel = new BroadcastChannel("loginEvent"); //2监听这个频道 channel.onmessage = (e) => { console.log(e) } // 3发送字符串 channel.postMessage("login");