🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## [**window-open**](https://electronjs.org/docs/api/window-open) >弹出子窗口 渲染主窗口index.html ``` .... <button onclick="openNewWindow()">弹出窗口</button> <button onclick="closeWindow()">关闭窗口</button> <script src="renderer/index.js"></script> .... ``` index.js ``` const wb=document.querySelect("#wb"); let subwin; function openNewWindow(){ subwin=window.open("popup_page.html","popup"); } //message参数接受子窗口的消息 window.addEventListener("message",(msg)=>{ console.log("接受到的消息",msg); }) function closeWindow(){ subwin.close(); } ``` popup_page.html ``` .... <button onclick="sendMessageTopParent()">点击传递消息</button> <script> //子窗口与父窗口之间的消息传递 function sendMessageTopParent(){ window.opener.postMessage({ type:1, message:"这是来自子窗口的消息" }); } </script> .... ``` ## [**BrowserWindowProProxy**](https://electronjs.org/docs/api/browser-window-proxy) >操作子窗口