ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## [**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) >操作子窗口