#The back button does not work

83 messages · Page 1 of 1 (latest)

elfin grove
#

Hi, I'm having a problem with the Back button, I'm using in main.js command go.Back, but when interacting with the site, the button in the menu stops working, please tell me how to fix it?

lament mango
#

any error?

#

we can't help you to fix anything if you share nothing

elfin grove
#

No, there are no errors, it just stops functioning, I can record a video for a detailed study of this problem

lament mango
#

share your code instead.

elfin grove
#

Ok

#

const { app, BrowserWindow, Menu, screen, ipcMain } = require('electron');
const path = require('path');

let win;

function createWindow() {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;

win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
        nodeIntegration: false,
        contextIsolation: true,
        preload: path.join(__dirname, 'preload.js')
    }
});

win.loadURL('https://ru.tradingview.com/chart/Irhk2lYq/');

const template = [{
        label: 'Назад',
        click: () => {
            win.webContents.goBack();
        }
    },
    {
        label: 'Выход',
        click: () => {
            win.close();
        }
    }
];

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

win.on('close', (e) => {
    e.preventDefault();
    win.destroy();
});

ipcMain.on('close-window', () => {
    win.close();
});

}

app.whenReady().then(() => {
createWindow();

app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
        createWindow();
    }
});

ipcMain.on('goBackHomeBoi', (event, arg) => {
    win.webContents.goBack();
    event.sender.send('WentBack', 'Done');
});

});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

chilly finch
#

why do you think it doesnt work?

elfin grove
#

This is one of the files if you hint that the project is not complete, and since I tried different options, nothing comes to mind. I figured out the Exit button thanks to .destroy, and I don't understand what to do with this one

lament mango
#

it doesn't answer the question

elfin grove
#

It turns out that when I start to expand one of the graphs and interact with the internal content of the site, the back button is automatically disabled in the console, there are no errors observed

lament mango
#

in the console?

elfin grove
#

yes

lament mango
#

the button is in the console?

#

what console?

elfin grove
#

no, I run the test in cmd (console) via npm start

chilly finch
#

why do you think back button doesnt work?

#

and what back button you talked about?

elfin grove
#

I'm sorry, the main domain is completely different there, the personal account in which the links are, I'll fix it now and show you

lament mango
#

??

elfin grove
chilly finch
#

you dont need back button for that

#

use react to open other pages

elfin grove
#

This is the main page that the user gets to, in simple words, the Home page, where he can navigate through the rest of the charts, but when switching to the chart and interacting with it, it does not work to return to the main site rusbafet.ru , where all graphs are displayed

chilly finch
#

you should use website navigation

elfin grove
#

the charts they click on are on tradingview, how to use navigation if it's not a single site?

chilly finch
#

but you know what main site is

#

instead of goBack use loadUrl to load main page

elfin grove
#

I tried to use it, but it still does not send this signal and the button does not work

#

Now I'll try again, assign the "Back" button instead of go.back is loadUrl

#

No, it didn't help

chilly finch
#

what doesnt work?

elfin grove
chilly finch
#

errors?

elfin grove
#

no

chilly finch
#

why do you think it doesnt work then?

elfin grove
#

There are no errors, I click and it just doesn't work and that's it

chilly finch
#

add console.log into click handler

elfin grove
#

It gave out this ╨E╨░╨╢╨░╤In╨░ ╨║╨╜╨╛╨┐╨║╨░ "╨ E╨░╨╖╨░╨┤"

chilly finch
#

use english

elfin grove
chilly finch
#

english words in console.log

elfin grove
chilly finch
#

so its work

elfin grove
#

No, it doesn't work, now I'll record a video it will be clearer

chilly finch
#

what electron version it is?

elfin grove
#

"electron": "^24.4.0"

chilly finch
#

does it work same withhttps://electronjs.org ?

elfin grove
#

I'll try it now

chilly finch
#

if problems because of charts it is not electron issue

#

you can try to .stop()

#

before loading new page

elfin grove
#

Please describe this method in more detail

elfin grove
# chilly finch if problems because of charts it is not electron issue

I don't see any problem with the charts, they work and work, all this runs in Electron, so why doesn't the "Back" signal reach the main page. There was a similar problem with the "Exit" button, I solved it this way https://stackoverflow.com/questions/41937111/electron-close-button-not-working
The answer of the author James Shaji helped me in this case and now the "Exit" button works very well

chilly finch
#

have you read this?

#

same way you can just do win.destroy()

#

without preventing close event

#

if site A work as expected and site B doesnt

#

problem with a site B

elfin grove
#

Yes, I used window.close() before, but it didn't work

chilly finch
#

without issue reproduction i cant tell you more

elfin grove
#

What is necessary for this? Should I provide the sources?

chilly finch
#

no

#

i need small part of your site that break default behavior

#

then put it into electron-fiddle

elfin grove
chilly finch
#

in case of that page

#

loadURL work as expected

elfin grove
#

You tried to click on the graph and stretch it, authorization is needed, without authorization it worked for me too

chilly finch
#

yes

elfin grove
#

Which version have you tested through?

chilly finch
#

24.4.0

elfin grove
#

And if you try a newer or an older one, an error may be displayed?

chilly finch
#

in case that home doest work on site itself

#

i dont think its problem with version

#

something prevent page to unload

elfin grove
#

I don't know what it could be, I will test with other versions and look for the reason, maybe I will find something, thank you for your help, if you find the reason, please let me know

chilly finch
#

add ```
win.webContents.on("will-prevent-unload", (e) => {
e.preventDefault();
});