ajay
ajay

Reputation: 101

Electron: Opening html page in BrowserWindow on click native menu item

I am new to electron and I am not able to figure out how to open a particular web page in BrowserWindow when native menu item is clicked.

Could anyone help me with this.

Regards, Ajay

Upvotes: 0

Views: 2644

Answers (1)

rawel
rawel

Reputation: 3033

use loadUrl method of the BrowserWindow inside your click event.

eg:

  win = new BrowserWindow({width: 800, height: 600})

  const template = [
    {
      label: 'Custom',
      submenu: [
        {
          label: 'navigate',
          click () 
          {
            win.loadURL('https://electron.atom.io');

          }
        }

      ]
    }
  ]

  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)
    // and load the index.html of the app.
  win.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }))

Upvotes: 1

Related Questions