Link to home
Start Free TrialLog in
Avatar of xenia27
xenia27Flag for Taiwan, Province of China

asked on

How can I close IE??

Hi,

I would like to know how can I terminate IE window when my JApplet is terminated...
SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you'll need to use javascript
you should be able to call self.close() when the page is unloaded.
no applet required :)
Avatar of xenia27

ASKER

"self.close()" is a function in Java??
something like:

<BODY onunload="javascript:self.close()">
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> you'll need to use javascript
See the link of my first comment
>> See the link of my first comment
...in case you want to do it from within java
> ...in case you want to do it from within java

thers no need, it just adds extra complication.
objects is right, you need javascript to close the window, either self.close() or window.close(). The link zzynx suggested only works under Netscape and only if you use netscape classes, which makes your applet non-portable to other browsers.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of x4u
x4u

> The link zzynx suggested only works under Netscape and only if you use netscape classes
Sorry but thats not true. It works with the Sun Java plugin and with the MS Java VM as well. The name of this package has only historical reasons.
Interesting... That's something I didn't know. Can you give me some references since I can't find anywhere the JSObject in the online javadocs (1.4.2).
If you're using the Sun JDK/JRE 1.4, the jar containing JSObject.class is located under jre/lib and it's called plugin.jar.
Btw, x4u thanks for the correction. I was out for dinner.
>>Can you give me some references since I can't find anywhere the JSObject in the online javadocs
http://www.jguru.com/faq/view.jsp?EID=272727
So, xenia

JSObject win = (JSObject) JSObject.getWindow(this);
win.eval("self.close();");
Yes I found it, thanks both.
In case you want to use JSObject, you need to add the mayscript attribute to your applet tag in the html file and put the plugin.jar into your classpath to get it compiled.
<applet code="Some.class" width=100 height=100 mayscript>
...
Avatar of xenia27

ASKER

Question,

How can I put javascript into my codes...I'm using VisualCafe...>"<...really have no idea how I can do so...
You don't need to if you want to close IE the way I proposed.
At the place/moment you want the IE to close you write (in your java code):

JSObject win = (JSObject) JSObject.getWindow(this);
win.eval("self.close();");

and as x4u remarked:
- put the plugin.jar into your classpath to get it compiled
- add the mayscript attribute to your applet tag in the html file

> How can I put javascript into my codes...I'm using VisualCafe...>"<...really have no idea how I can do so...

You do not need to write javascript into java code even if you follow all three suggestions here. If you need to write some JavaScript that will only be minimal, something like:

<html>
   <body onLoad="window.close();">
   </body>
</html>

but this will be in another page, as suggested by the comment I posted.
> How can I put javascript into my codes

You don't need to make any change to your applet.
What you want can be more easily achieved by adding the above javascript to your html, and *not* your applet.
Avatar of xenia27

ASKER

OK...going to try now...^^
Thank you