Close browser window from applet

I have a simple applet that is called
from another application through HTML.
When the applet is done, I'd like to have
it exit and close its browser window.
How is this done? I tried System.exit(),
and that didn't do it. Neither did
destroy().

The only thing I can think of is to have a function defined in JavaScript on your html page and have the applet call the method. For you to be able to do this you will have to have a MAYSCRIPT set in your applet tag.
IE:
<script language="JavaScript">
function closeWindow()
window.close();
</script>
<APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"
MAYSCRIPT>
</APPLET>
In your applet:
Make sure that you import the following.
import netscape.javascript.*;
JSObject win = JSObject.getWindow( this );
win.call( "closeWindow", null );// Calls the closeWindow() on the HTML page.

Similar Messages

  • Getting hang/crash problem when I try to close browser window from applet

    I have a small Apllet that has a button that calls a Javascript function in the opening window, to close the window in which it is loaded.
    The Applet window is a PopUp window from one of my application's window. First time I start my application and load that Applet the button works fine. It calls the Javascript method and the Method closes the window using the self.close() method.
    But now if I open the applet window again and click on the button to close the windows, it hangs. I put in trace statements and saw that it hangs on JSObject.getWindow() window.
    I am using JDK Plugin 1.4.2_07 and 5.0 , if I work out on IE browser, it works fine.But when I use firefox or mozilla it gives problem of hanging/crashing.
    Note that in case of 1.4.2_07 this problem experienced some times but in case of 5.0 it gives always for other than IE browser.
    Please, if somebody could give me some clue about why this would happen, I will really appreciate that. and code related to this is given below
    import javax.swing.JApplet;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import netscape.javascript.JSObject;
    public class TestApplet extends JApplet implements ActionListener{
    protected JButton closeButton = null;
    protected JSObject win = null;
    private JFrame frame = null;
    private boolean alreadyClosed = false;
    public void init(){
    this.win = JSObject.getWindow(this);
    this.closeButton = new JButton("Close Browser Window");
    this.add(this.closeButton);
    this.closeButton.addActionListener(this);
    frame = new JFrame("Test Frame");
    frame.setSize(300, 400);
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.out.println("windowClosing");
    alreadyClosed = true;
    TestApplet.this.stop();
    frame.show();
    public void actionPerformed(ActionEvent ae){
    stop();
    public void stop() {
    if (!alreadyClosed) {
    alreadyClosed = true;
    frame.dispose();
    closeLaunchedBrowser();
    System.gc();
    System.runFinalization();
    private void closeLaunchedBrowser() {
    final TestApplet thisObject = this;
    Runnable r = new Runnable() {
    public void run() {
    try {
    JSObject win = (JSObject)JSObject.getWindow(thisObject);
    if (win != null && win.toString() != null) {
    //win.eval("top.opener=self;self.close();");
    //win.call("close", null);
    win.eval("self.close();");
    } catch (Exception e) {
    Thread t = new Thread(r);
    t.start();
    Thanks.

    I am waiting for any reply. I have tried for all these below options still I am getting Problem. I heard this is because of javascript, it wont call methods more times .Thats
    why I need other than JSObject or java script solution.If some one know anything about this or any modifications I have to made for the below options to avoid that problem please let me know.
    // URL durl = new URL(thisObject.getCodeBase(), "test/CloseMe.htm");
    // System.out.println("URL :" + durl.toString());      
    // thisObject.getAppletContext().showDocument(durl);
    //     thisObject.getAppletContext().showDocument(new URL("javascript:window.close();"), "_self");
    //win.eval("top.opener=self;top.close();");
    //win.call("close", null);
    //Object[] args = { "close", new Integer(50) };
    // win.call("setTimeout", args);
    //win.eval("setTimeout("close", new Integer(50));");
    If it is the problem of JRE I just need it should work on 1.4.2_01 or higher.
    thanks.

  • How to close Browser window from Applet ?

    I am looking to close the browser window based on an action within applet . any ideas ?

    Hi U can close the Browser window in which the applet
    opened
    try this,
    Just call this where u want to close the browser
    import java.net.*;
    URL url;
    url=getCodeBase();
    try{                    getAppletContext().showDocument (new URL (url+"close.htm"));
    }catch(MalformedURLException e){showStatus("no file");}
    In the close.htm have this code
    ///close.htm
    <HTML><SCRIPT>
    <!--
    window.close();
    //-->
    </SCRIPT></HTML>

  • Close Browser window from JApplet

    I'm writing an applet that has to launch an asp page to accomplish a task. Is there any way to run this page with an AppletContext, (showDocument()) and then close the browser window without the user seeing the window open?
    Thanks,
    eemanuel81

    launch an asp page to accomplish a task.You can use the URL object in Java, this will make the http request to the asp page sharing the browser's cookie (in IE and Moz on windows).
    If the applet needs to make a connection to antother server than the one the applet came from you might be in trouble. You have to sign the applet or the user needs to set up a policy for it.
    Signing your applet:
    http://forum.java.sun.com/thread.jsp?forum=63&thread=524815
    second post
    Posting data:
    http://javaalmanac.com/cgi-bin/search/find.pl?words=url+post

  • Closing a browser window from applet

    i have applet opened in a IE browser.
    The applet contains TOOL BAR and one of the buttons in it is EXIT.so when i click this exit button the browser window should close.
    if any one has idea about it please let me know along with sample code.
    thanx in advance.

    try this
    on click of that exit button in action event write this
    System.exit(0);

  • Close browser window when applet closes (seperateFrame=True)

    Hello,
    Does anyone know a way to close the parent browser window when the java applet closes when the config setting seperateFrame=True?
    Thanks

    Do a little search in the forum, there are 100s of solutions on how to close the browser window.

  • Opening browser windows from applet

    I have 2 questions
    1) Does anyone know, what do I have to do to force my java applet to open new browser window with specified url ?
    2) Is any java class, which renders HTML files ? I'm trying to open some document in frame inside applet and I don't know if i have to write this renderer by myself.

    for your second question, I dont know if there is a specific HTML class but SAXParser makes reading xml very easy and you probably should have much trouble writing a class to read html.

  • Close browser window from webdynpro

    Hi
    Is it possible to close a brower window on click of a button in webdynpro
    Thanks
    Murali

    launch an asp page to accomplish a task.You can use the URL object in Java, this will make the http request to the asp page sharing the browser's cookie (in IE and Moz on windows).
    If the applet needs to make a connection to antother server than the one the applet came from you might be in trouble. You have to sign the applet or the user needs to set up a policy for it.
    Signing your applet:
    http://forum.java.sun.com/thread.jsp?forum=63&thread=524815
    second post
    Posting data:
    http://javaalmanac.com/cgi-bin/search/find.pl?words=url+post

  • Open a new browser window from applet

    Anybody know how to open a new Netscape window by pressing a button in an applet? Which class handles it?
    Thanks a lot.
    wz

    http://forum.java.sun.com/thread.jsp?forum=54&thread=106906
    http://forum.java.sun.com/thread.jsp?forum=54&thread=272870
    http://forum.java.sun.com/thread.jsp?forum=54&thread=272829

  • Closing browser window from an Applet?

    I've written a series of applets that perform different functions. I placed a button on each applet with the purpose to close the window in which that applet is running. However I don't even know where to start looking to find out how to make my applet close it's own browser window. I know how to open a new browser window from an applet but not vice versa.
    Can anyone help please?
    Mark.

    Right, I sort of tracked down some code that uses getMethods to allow me to invoke a Javascript command. It is not pretty and took a little bit of editing to get to work but it does the job without putting JS stuff into my HTML.
    However it is causing some problems. If I open one of my other applets it will only let me close that window and the previous applets ceases to respond at all. I think this may be because the invoke gets the JSObject which is the window and somehow having more than one applet open in different windows is causing it to get confused and is locking the first window and only responding to the second.
    I have seen a much simpler method that uses:
    import netscape.javascript.*;
    and JSObject to get the window but my compiler complains about the import. Any further suggestions or an example would be welcome as my current solution is a bit limited as you can effectively only have one window open at a time which doesn't suit my needs.
    Many thanks.
    Mark.

  • Close a browser  window from a servlet

    I am newbie and am trying to close the browser window from my servlet without prompting as my servlet is designed to run as a batch app.
    The servlet is invoked by a scheduling agent and performs the batch function , but leaves the browser window open . I
    need help
    Thanks
    VK

    I am newbie and am trying to close the browser
    window from my servlet without prompting as my
    servlet is designed to run as a batch app.
    The servlet is invoked by a scheduling agent and
    performs the batch function , but leaves the browser
    window open .I don't see the problem with that. The users can easily close the browser if they want to. It's possible that some Javascript could be used to close the browser window but it's user-unfriendly and shouldn't normally be done.

  • How do I open a new browser window from Flash

    I wish to open a new browser window from Flash and when the new window closes to return to the location from whence I started.
    ThomasChen

    The command to open a new window would be the "_blank" part of a command to link to a web page in the code below.
    navigateToURL(new URLRequest("http://www.anothersite.com", "_blank"));
    As far as the new window closing and getting back to where you were in the original window, I don't understand where that original window might have gone to... You should be wherever you last left it.

  • Close external window from source application

    I am trying to close the external browser window from the source application (wda). But it seems that I am unable to close from the source window, just by calling close method. This close method has a parameter '  control_to_focus_id' . I am not sure what exactly it needs to be filled with.
    But anyways these act like two separate sessions and can't communicate any longer.
    Is there a way for me to control the external window and close on some user action at source/
    Any inputs would be highly appreciated.
    Thanks

    Hi,
    External window is independent of source window, you cannot control it from source application. May I know what is your requirement!
    Regards,
    Kiran

  • Open new browser window from a JApplet

    Hi,
    I want to open a new browser window from a JApplet.My first thought was to use the Live Connect technology but it worked only with simple applets not with JApplets.Then i tried it by getting the Applet context (getAppletContext() method) but it still didn't work with JApplet...(it worked with Applet).I believe it has something to do with the applet security but i haven't yet figured it out.
    For example when i call the getAppletContext() method from a JApplet i get an java.security.AccessControlException ... .Thanks

    I must correct myself now :).
    The getAppletContext() method does work with JApplets too.Still , i have problems with the Live connection alternative.It seems that it by importing the netscape.javascript package i get the security eror that i mention above...

  • Closing browser window from Flash movie on CD

    I have to put a flash lesson I created on a cd for a client and while testing it I noticed that my exit button in the movie no longer seems to function.
    This is my close window function
        function closeWindow(evt:Event)
            var url:String = "javascript:window.opener=self; window.close()";
            var request:URLRequest = new URLRequest(url);
            try
                navigateToURL(request, "_self");
            catch (e:Error)
                trace("Error occurred!");
    Can anyone tell me why this wouldn't work when the movie is launched in a browser window from a CD?

    Fi it is at all possible you cannot do that with url request.
    Try using ExtrenalInterface class:
    ExternalInterface.call("javascript:...");
    It may not waork though depending on security settings and embed parameters.

Maybe you are looking for

  • Follow-up: Starting, Launching and Switching ...

    Follow-up: Starting, Launching and Switching ... Messing around with the Windows UI - not a feature problem, but a provisioning problem! Now start listening and please fix it this time!  (Is it still program managers or people in power designing the

  • Automatic creation of customer from BP  - How to match the fields? CVI

    I am trying to create a customer from a BP. I am done all the customizing steps. Now I need to match the fields. There is an error message with this field KNA1-SPRAS that doenst match what should I do? I have read this "In particular you have matched

  • ECR approval by multiple people in MS outlook

    Hi, I am looking for information for ECR appproval by multiple people in MS outlook to set system status as change possible,  approve ECR, convert ECR thru workflow. Any inputs will be really helpful. Anirudh,

  • Query in data Loading.

    Hi All, I  have a query on data loading. Right now the delta is running in BI Production.Suppose some records are missing in ODS,then i can go for select conditions in Info package and selecting the repair Full request. Query No 1 : Instead of runnin

  • I can not monitor the results of color correction made ​​in Color

    I can not monitor the results of color correction made in Color come out the Blackmagic HD exrteme 3. Since the Final I have cut the output correctly. I made the settings in the setupproject and setings but I had no success.