Currently Being Moderated

Handle HTML modal dialogs

VERSION 1

Created on: Jun 4, 2009 4:17 PM by Vladimir Ikryanov - Last Modified:  Jun 4, 2009 4:19 PM by Vladimir Ikryanov

The sample shows how to handle showing modal dialog windows that were opened through window.showModalDialog or window.showModelessDialog JavaScript function:

/*
 * Copyright (c) 2000-2009 TeamDev Ltd. All rights reserved.
 * TeamDev PROPRIETARY and CONFIDENTIAL.
 * Use is subject to license terms.
 */
import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.dom.HTMLDialog;
import com.jniwrapper.win32.ie.dom.HTMLDocument;
import com.jniwrapper.win32.ie.event.HtmlDialogEvent;
import com.jniwrapper.win32.ie.event.HtmlDialogListener;
 
import javax.swing.*;
import java.awt.*;
 
/**
 * The sample shows how to handle showing modal dialog windows
 * that were opened through {@code window.showModalDialog} or
 * {@code window.showModelessDialog} JavaScript function.
 * <p/>
 * In this sample we receive an event when the dialog is shown,
 * print the dialog's document title in console and close the
 * opened modal dialog window.
 */
public class HandleModalDialogSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(browser, BorderLayout.CENTER);
        frame.setSize(600, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
 
        browser.setHtmlDialogListener(new HtmlDialogListener() {
            public void show(HtmlDialogEvent event) {
                HTMLDialog dialog = event.getDialog();
                // Receiving document of the opened modal dialog window
                HTMLDocument document = dialog.getDocument();
                System.out.println("document title = " + document.getTitle());
                // Closes modal dialog window
                dialog.close();
            }
        });
 
        browser.executeScript("window.showModalDialog('http://www.google.com', 'name', '');");
    }
}
 

Average User Rating
(1 rating)




There are no comments on this document

More Like This

  • Retrieving data ...