Examples‎ > ‎

Intercept JavaScript Dialogs

import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.event.DialogEventHandler;
import com.jniwrapper.win32.ui.MessageBox;
import com.jniwrapper.win32.ui.Wnd;

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

/**
 * The sample demonstrates how to suppress JavaScript alert, confirmation and error dialogs.
 */
public class DisableJavaScriptDialogsSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        browser.setDialogEventHandler(new DialogEventHandler() {
            public int showDialog(Wnd wnd, String title, String text, int type) {
                return MessageBox.OK;
            }
        });
        
        JFrame frame = new JFrame();
        frame.getContentPane().add(browser, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}