Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单个Electron createWindow()实例变量_Javascript_Electron - Fatal编程技术网

Javascript 单个Electron createWindow()实例变量

Javascript 单个Electron createWindow()实例变量,javascript,electron,Javascript,Electron,我创建了一个Electron应用程序,主要是一个web应用程序,它与Electron应用程序进行了少量集成。大多数人只是通过带有loadURL的浏览器窗口加载网站 但是,对于生成的每个CreateWindow(它们具有相同的内容),我需要变量来影响单个窗口,而不是所有窗口 当前,如果我更改let变量,则所有窗口的变量都会更改。我不确定如何使变量只在特定窗口中使用特定值进行更新和使用 e、 g.如果我在一个窗口中设置userId=1,当我通过web应用程序发送ipc消息时,它在第二个窗口中也会更改

我创建了一个Electron应用程序,主要是一个web应用程序,它与Electron应用程序进行了少量集成。大多数人只是通过带有loadURL的浏览器窗口加载网站

但是,对于生成的每个CreateWindow(它们具有相同的内容),我需要变量来影响单个窗口,而不是所有窗口

当前,如果我更改
let
变量,则所有窗口的变量都会更改。我不确定如何使变量只在特定窗口中使用特定值进行更新和使用

e、 g.如果我在一个窗口中设置userId=1,当我通过web应用程序发送ipc消息时,它在第二个窗口中也会更改。我不确定这里的最佳逻辑是什么。

编辑:

如果打开一个窗口的两个独立实例,如下图所示,则变量应分别位于各自的字段中

只需在
main
过程中更改位置即可

// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 })

// and load the index.html of the window.
win.loadURL('https://google.com')

// Create the browser window.
win2 = new BrowserWindow({ width: 800, height: 600 })

// and load the index.html of the window.
win2.loadURL('https://youtube.com')
编辑2

因此,根据评论,我想我为您找到了一个解决方案。如果希望每个窗口都有单独的变量,可以将它们存储在窗口对象中。只需确保在销毁对象之前提取它们(如果您仍然需要它们:)


我突然想到。。。您是否在主进程中有一个变量,并期望它在所有窗口中都不同?@Elias是的,不确定我在想什么。但这正是我需要的。因为我可以调用同一个浏览器窗口,它们将在不同的窗口中工作,但不会在变量中工作。我已更新了我的答案(编辑2)
// Create the browser windows
let win_0 = new BrowserWindow({ width: 800, height: 600 });
let win_1 = new BrowserWindow({ width: 800, height: 600 });

// Set variables
win_0.UID = 'ASDF-ASDF';
win_1.UID = 'QWER-QWER';

// And now you can just get them like
console.log(win_0.UID, win_1.UID);