javascriptnode.jselectron

Is it possible to disable zoom in/out functionality in a Electron electron-quick-start JS app?


This question is specific to electron-quick-start, so it's not a duplicate.

I'm in the very first steps of JS desktop apps with https://github.com/electron/electron-quick-start, I have the code and I can run the app on my mac(hine).

I've note It's possible to zoon in/out the text on the app, which is a feature common to web. Not so common to desktop apps.

How do I disable that behavior?


Solution

  • Add the following to the JavaScript file that your rendered html file is sourcing in (see, main process vs renderer process).

    var webFrame = require('electron').webFrame;
    webFrame.setVisualZoomLevelLimits(1, 1);
    

    In your case, it's renderer.js for the electron-quick-start app.

    Documentation: https://github.com/electron/electron/blob/master/docs/api/web-frame.md#webframesetzoomlevellimitsminimumlevel-maximumlevel