[英]how to send value as a parameter to loadURL() of electron main.js file from node js file?
const electron = require("electron");
const { app, BrowserWindow } = electron;
const path = require("path");
function createWindow() {
// Create the browser window.
//window 1
let win1 = new BrowserWindow({
width: 1000,
height: 600,
});
win1.loadURL("https://twitter.com/");
win1.on("closed", () => {
win1 = null;
});
}
app.on("ready", createWindow);
i need to get url from frontend and access in node.js and pass to main.js loadURL() as a parameter.我需要从前端获取 url 并在 node.js 中访问并传递给 main.js loadURL() 作为参数。
What do you mean by this get url from frontend and access in node.js.从前端获取 url 并在 node.js 中访问是什么意思。 If my recognition is correct, I think you are going to read url from the renderer and send this to Electron main process to create BrowserWindow based on that url.
如果我的识别是正确的,我认为您将从渲染器读取 url 并将其发送到 Electron 主进程以基于该 url 创建 BrowserWindow。 So communication between renderer and main.
所以渲染器和主之间的通信。 Use this ipcRenderer and ipcMain .
使用这个ipcRenderer和ipcMain 。 You can send the url using ipcRenderer like this
您可以像这样使用ipcRenderer发送 url
...
const { ipcRenderer } = require('electron');
function sendUrlToMain(url) {
ipcRenderer.sendSync('sendUrlToMain', url);
return res;
}
...
Then add this to main.js然后将其添加到 main.js
ipcMain.on('sendUrlToMain',(event, arg) => {
let win1 = new BrowserWindow({
width: 1000,
height: 600,
});
win1.loadURL(arg);
win1.on("closed", () => {
win1 = null;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.