electron 点击后电子重定向页面

1sbrub3j  于 9个月前  发布在  Electron
关注(0)|答案(1)|浏览(114)

我正在尝试将nodejs应用程序转换为桌面应用程序。
所以,我想重定向新的页面,点击按钮后.我试过这个

来自entry.html

<button type="button" class="btn btn-success" id="goto-add-customer">Select</button>

    </div>

    <script>
        const { ipcRenderer } = require('electron');
        document.getElementById('goto-add-customer').addEventListener('click', () => {
            ipcRenderer.send('open-new-page');
        });
    </script>

这里是我的main.js

// main.js
const { app, BrowserWindow, ipcMain } = require('electron');

let mainWindow;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    width: 1920,
    height: 1080,
    webPreferences: {
      nodeIntegration: true
    }
  });

  mainWindow.loadFile('entry.html');

 
  mainWindow.on('closed', () => {
    mainWindow = null;
  });

  ipcMain.on('open-new-page', () => {
    mainWindow.loadFile(path.join(__dirname, 'addCustomerPage.html'));
  });
});

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

但是,当我点击按钮时,什么也没有发生。你能帮帮我吗?

gcmastyq

gcmastyq1#

如果你需要的只是转到另一页。你其实不需要这些只是改变你的html到

<button type="button" class="btn btn-success" id="goto-add-customer">Select</button>

    </div>

    <script>
     
        document.getElementById('goto-add-customer').addEventListener('click', () => {
            window.location="./addCustomerPage.html";
        });
    </script>

这就是全部,您可以从main.js中删除该部分
我可以用html -> main的方式解释如何做到这一点,但在你的情况下并不需要。实际上,尽可能地使其跨平台,而不是电子特定的。如果你仍然需要它这样的评论,我会解释

相关问题