Disable pinch zoom in webkit (or electron)

后端 未结 9 2354
北荒
北荒 2020-12-29 02:23

Is there any way to disable pinch zoom in an electron app?

I can\'t get it to work from inside the web-view with normal javascript methods as described here: https:/

9条回答
  •  滥情空心
    2020-12-29 02:50

    Answer from GitHub:

    "If you are looking for a way how to prevent zoom from main process, you can use:"

    const webContents = mainWindow.webContents;
    webContents.on('did-finish-load', () => {
      webContents.setZoomFactor(1);
      webContents.setVisualZoomLevelLimits(1, 1);
      webContents.setLayoutZoomLevelLimits(0, 0);
    });
    

    mainWindow is variable where you have new BrowserWindow, e.g.:

    const mainWindow = new BrowserWindow({
      width: 440,
      height: 750,
      // ...
    });
    
    const webContents = mainWindow.webContents;
    webContents.on("did-finish-load", () => {
      webContents.setZoomFactor(1);
      webContents.setVisualZoomLevelLimits(1, 1);
      webContents.setLayoutZoomLevelLimits(0, 0);
    });
    

提交回复
热议问题