oli venöl
oli venöl

Reputation: 25

Zoom Function in a Webview with Electron

I'm trying to create a zoom in and a zoom out button for my webview in my Electron app.

Currently, I did it like this but getZoomFactor always returns undefined. Is there another way of creating these two zoom buttons?

function zoomIn() {
    const webview = document.querySelector('webview');
    let actualZoom = webview.getZoomFactor();
    if (actualZoom == null) {
        actualZoom = 1;
    }
    webview.setZoomFactor(actualZoom + 1);
}

function zoomOut() {
    const webview = document.querySelector('webview');
    let actualZoom = webview.getZoomFactor();
    if (actualZoom == null) {
        actualZoom = 1;
    }
    webview.setZoomFactor(actualZoom - 1);
}

Upvotes: 1

Views: 1227

Answers (1)

user10747134
user10747134

Reputation:

The WebView's getZoomLevel takes a callback instead of returning a value.

.getZoomLevel(callback) callback Function

zoomLevel Number Sends a request to get current zoom level, the callback will be called with callback(zoomLevel).

Upvotes: 1

Related Questions