fb

Ads

Pages

Close browser using Java applet

You can Close browser using Java applet
Here's the code


import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import netscape.javascript.JSObject;
class CloseApplet extends Applet
implements ActionListener{
protected Button closeButton = null;
protected JSObject win = null;
public void init(){
this.win = JSObject.getWindow(this);
this.closeButton = new Button("Close Browser Window");
this.add(this.closeButton);
this.closeButton.addActionListener(this);
} // ends init(void)
public void actionPerformed(ActionEvent ae){
this.win.eval("self.close();");
}
} // ends class CloseApplet

 

//////////////////////////////////////////////////////

and the HTML need to have MAYSCRIPT enabled.


//////////////////////////////////////////////////////
 

<HTML>
<HEAD>
<TITLE>Integre Technical Publishing</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<DIV ALIGN="CENTER">
<APPLET WIDTH="150" HEIGHT="30" CODE="CloseApplet.class"
CODEBASE="java/" MAYSCRIPT>
</APPLET>
</DIV>
</BODY>
</HTML>
 

//////////////////////////////////////////////////////
 

Here's the API:

<http://home.netscape.com/eng/mozilla/3.0/handbook/plugins/doc/Package-netscape.javascript.html>
It's small enough that you could include it in your JAR if you'd like. But most users will even have it on
their systems.
It says "Netscape," but I know that IE understands it fine.

0 comments:

Post a Comment