Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

INFO: Calling System.exit() from Applet Exits Internet Explorer


View products that this article applies to.

Summary

If you have a signed (trusted) applet and your applet calls System.exit(), it will cause Internet Explorer to exit.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Save the following to a file named testApp.java:
          import java.applet.Applet;
          import java.awt.*;
          public class testApp extends Applet
          {
             Button b1;
             public void init ()
             {
                b1 = new Button("Press");
                add("Center", b1);
             }
             public boolean action(Event ev, Object arg)
             {
                if (arg.equals("Press"))
                {
                   try
                   {
                      System.out.println("Exiting now.");
                      System.exit(0);
                   }
                   catch (Exception ex)
                   {
                      if (ex instanceof SecurityException)
                         System.out.println("Cannot exit browser");
                      else
                         ex.printStackTrace();
                   }
                }
                return true;
             }
          }
    						
  2. Compile the file.
  3. You will need to use the tools from the SDK for Java to cab and sign the applet.
  4. Run the applet in Internet Explorer 4.0x.
  5. Notice that when you click the Press button your browser session will terminate.
NOTE: If you run the applet and it is not cabbed and signed, your browser session will not terminate when you press the button labeled "Press." Rather, you will observe an error message in the javalog, which may be viewed (in Internet Explorer 4.01) by opening the Java Console.

↑ Back to the top


References

HOWTO: Make your Java Code Trusted in Internet Explorer
For more information on Cabbing and Signing a Java Applet, please refer to the SDK for Java documentation at the following Web site:

↑ Back to the top


Keywords: kbarttypeinf, kbcode, kbinfo, KB189167

↑ Back to the top

Article Info
Article ID : 189167
Revision : 6
Created on : 11/14/2005
Published on : 11/14/2005
Exists online : False
Views : 512