Electron: window.setTitle() is ignored when website has title node

Created on 6 May 2015  路  3Comments  路  Source: electron/electron

Having the following HTML

<html>
  <head>
    <title>bar</title>
  </head>
  <!-- ... -->
</html>

And invoking window.setTitle('foo'); somewhere within the main process, title remains bar instead of being set to foo

setTitle() works correctly if the HMTL file doesn't contain a title-node

Most helpful comment

Here a complete example:

var win = new BrowserWindow({
  width: 800, 
  height: 600,
  title: 'My fixed title'
});

win.on('page-title-updated', (evt) => {
  evt.preventDefault();
});

All 3 comments

works when putting setTitle within webContents did-finish-load event.

For future reference, the correct way to set window title is to prevent it from automatically updating to page's title first:
https://github.com/atom/electron/blob/master/docs/api/browser-window.md#event-page-title-updated

Here a complete example:

var win = new BrowserWindow({
  width: 800, 
  height: 600,
  title: 'My fixed title'
});

win.on('page-title-updated', (evt) => {
  evt.preventDefault();
});
Was this page helpful?
0 / 5 - 0 ratings