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