Disable touchpad zooming in JcefBrowser

Planned

Hi, I managed to disable zooming triggered by Ctrl + MouseWheel in JcefBrowser through


jbCefBrowser.getComponent().addMouseWheelListener(e -> {
    if (e.isControlDown()) {
        jbCefBrowser.getCefBrowser().setZoomLevel(0.0);
        e.consume(); // Consume the event to prevent zooming
    }
});

But the touchpad event won't trigger this listener, how can I disable the touchpad zooming event?
And I find the page jiggles when I use ctrl + mousewheel, Is there a better method to lock the scale?
Thank you very much for any help!

0
2 comments

Hi,

It's the windowed mode(not OSR)? Right?

Unfortunately there is no JCEF API that could help to do that.

But I can suggest to use JavaScript to disable zooming, if you can inject some JS into your page.

<html lang="en">
<body>
<h1>Zooming is disabled on this page</h1>
<script>
    document.addEventListener('wheel', function (event) {
        if (event.ctrlKey) {
            event.preventDefault();
        }
    }, { passive: false });
</script>
</body>
</html>
0

You may also just execute this JS code once the browser loaded the page, if it doesn't break the page logic.

    document.addEventListener('wheel', function (event) {
        if (event.ctrlKey) {
            event.preventDefault();
        }
    }, { passive: false });
0

Please sign in to leave a comment.