0
I’m using Electron to develop an application where your goal is to leave some selected sites there.
Now I’m facing a problem that when I go to a link of one of the options that are in the application I can’t go back to the homepage, where you find the other options.
I’ve tried the following:
const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow();
mainWindow.loadURL(path.join('file://', __dirname, 'index.html'));
setMainMenu();
});
function setMainMenu() {
const template = [
{
label: 'Voltar para o Menu',
submenu: [
{
label: 'Menu Principal',
accelerator: 'Shift+CmdOrCtrl+H',
click() {
win = new BrowserWindow({ width: 1440, height: 800 })
win.loadFile('index.html')
}
}
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
Only this way it opens a new application and does not go back to the home screen, I wonder if it is possible to make this "back" button, in the native menu of Electron
new BrowserWindow
will open a new window, if you want to continue on the same screen, I thinkwindow.location.href ="/index.html"
maybe solve, but I realized that when you open a link, it opens already opens a new window, it would not be correct to just close it?– edson alves
@edsonalves added three images explaining the process that happens, I can’t tell you if closing it would work, but if this is an option, how can I do it ?
– Brenda Xavier
It goes something like this, I don’t know your version but basically you need to access the remote and get the current window:
let w = app.remote.getCurrentWindow(); w.close()
– edson alves
is really this way will not work, it closes the application and I need to return to the home page in case the "index.html"
– Brenda Xavier
Then the other option must serve
– edson alves
a doubt, this window.location.href = "/index.html" should go in the right main.js file?
– Brenda Xavier
In the click, in the same place where you already try to go pro index
– edson alves
Maybe it’s right
let w = app.remote.getCurrentWindow(); w.location.href ="index.html"
– edson alves
it is funny that it gives an error "Cannot read Property getCurrentWindow of Undefined", it seems that it does not know where is the page that should be closed
– Brenda Xavier
Let’s go continue this discussion in chat.
– edson alves