Note: Starting with Chromium 52, Backspace Navigation is disabled in the browser engine. That means that backspace navigation is no longer available in JxBrowser 6.12 and higher.(注意:从Chromium 52开始,在浏览器引擎中禁用了Backspace Navigation。这意味着JxBrowser 6.12和更高版本中不再提供退格导航。)


By default navigation on Backspace and Shift+Backspace is enabled. In order to disable navigation when user presses Backspace or Shift+Backspace use the following approach: (默认情况下,启用了Backspace和Shift + Backspace导航。为了在用户按下Backspace或Shift + Backspace时禁用导航,请使用以下方法:)

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.DefaultLoadHandler;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;

/**
 * The sample demonstrates how to handle navigation on Backspace and
 * Shift+Backspace.
 */
public class DisableBackspaceNavigationSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView browserView = new BrowserView(browser);
        browser.setLoadHandler(new DefaultLoadHandler() {
            @Override
            public boolean canNavigateOnBackspace() {
                return false;
            }
        });

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(browserView, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        browser.loadURL("http://www.google.com");
    }
}