Real'sHowTo AddThis Feed Button
Custom Search

Have a Java button close the browser windowTag(s): Javascript interaction


import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import netscape.javascript.*;

public class WinClose extends Applet 
        implements ActionListener{

Button wc = new Button("Close me");

public void init() {
 wc.setActionCommand("CLOSE");
 wc.addActionListener(this);
 add(wc);
 }

public void actionPerformed(ActionEvent e) {
  String command = e.getActionCommand();
  if (command.equals("CLOSE")) {
   JSObject win = (JSObject) JSObject.getWindow(this);
   win.eval("self.close();");
   }
  }
}
Try it here
blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2013
[ home ]