Javascript electron react应用程序多个子窗口,只能打开一个子窗口
我已经在react electron应用程序中打开了一个childwindow,但我想打开多个childwindow。我尝试过用道具动态命名childwindow框架名,但也不起作用 下面是子窗口类组件:Javascript electron react应用程序多个子窗口,只能打开一个子窗口,javascript,reactjs,electron,Javascript,Reactjs,Electron,我已经在react electron应用程序中打开了一个childwindow,但我想打开多个childwindow。我尝试过用道具动态命名childwindow框架名,但也不起作用 下面是子窗口类组件: export default class ChildWindow extends Component { containerEl = document.createElement('div'); styleEl = document.createElement('style'); extern
export default class ChildWindow extends Component {
containerEl = document.createElement('div');
styleEl = document.createElement('style');
externalWindow = null;
componentDidMount() {
this.externalWindow = window.open('', 'ChildWindow');
if (this.externalWindow)
{
this.containerEl.style.height = '100vh';
this.containerEl.style.width = '100vw';
this.externalWindow.document.body.appendChild(this.containerEl);
this.externalWindow.document.body.style.margin = '0';
this.externalWindow.onunload = () => this.props.onClose();
}
}
render() {
return ReactDOM.createPortal(this.props.children, this.containerEl);
}
}
以下是electron.js文件中的新窗口代码设置:
mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
if (frameName === 'ChildWindow') {
event.preventDefault();
Object.assign(options, {
// parent: mainWindow,
height: 700,
width: 400,
minHeight: 700,
minWidth: 400,
resizable: false,
frame: false,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
webSecurity: false,
nativeWindowOpen: true
}
});
const newWindow = new BrowserWindow(options);
event.newGuest = newWindow;
}
});
这里还有我在函数类中使用childwindow组件的代码:
<ChildWindow
onClose={closeCaptchaSolver}
>
<p>hoi</p>
</ChildWindow>
海